change color of one specific row in listview

Vodet

I have a listview (liste_joueurs), when i click on an item in the list, the row change color and become grey ( this is for the user, he can remenber on which row he click ).

It's not finish i have 12 button and each item on a list got a number, when i click on an item in the list one button appears and his text take the number of the player, here's a picture of the fragment.

enter image description here

If the user make a mistake, I have a onclickListener for the 12 button below and when I click on, the button disappears, but my problem is I need to find the good row corresponding to the number and change his color in white. How can i do this ?

Now let's see the code

In my fragment :

 // I take all the player in my database
 Cursor cursor = joueurDab.getAll();
 //I fill the listView with a cursorAdapter
 CursorListJoueur cl = new CursorListJoueur(context, cursor);
 liste_joueurs.setAdapter(cl);

The cursorAdapter :

public class CursorListJoueur extends CursorAdapter {

private CategorieDAO categorieDab;
public CursorListJoueur(Context pContext, Cursor c) {
    super(pContext, c, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    categorieDab = new CategorieDAO(context);
    return LayoutInflater.from(context).inflate(R.layout.row_player, parent, false);
//row_player is the xml file where I highlight row 
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

    Categorie categorie = this.categorieDab.selectionner(cursor.getInt( 6 ));

    ((TextView) view.findViewById(R.id.numero)).setText(String.valueOf(cursor.getInt(1)));
    ((TextView)view.findViewById( R.id.nom )).setText(cursor.getString(2));
    ((TextView)view.findViewById( R.id.prenom )).setText(cursor.getString( 3 ));
    ((TextView)view.findViewById( R.id.categorie )).setText(categorie.getNom());


    if( cursor.getInt( 5 ) == 1)
        ((CheckBox)view.findViewById( R.id.is_goal )).setChecked( true );
    else
        ((CheckBox)view.findViewById( R.id.is_goal )).setChecked( false );
}
}

The row_player.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
android:layout_width="match_parent"
//this ligne
android:background="@drawable/testlist"
android:layout_height="match_parent">

<TextView
    //etc ...

And finally testlist.xml i use this file for highlight my listview

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/darker_gray" android:state_selected="true"/>
    <item android:drawable="@android:color/darker_gray" android:state_activated="true"/>
    <item android:drawable="@android:color/darker_gray" android:state_pressed="true"/>
    <item android:drawable="@color/android:transparent"/>
</selector>

Thanks for your help

Erik Duisters

You have to set the background of the row you want highlighted via your adapter. If the user presses the wrong button change your adapter data (or tell it which row you want highlighted) and call notifyDataSetChanged().

The adapter can than set the row's background color to white in it's getView() function.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I permanently change the background color of a row in a Listview?

분류에서Dev

Change Cell Color Based on Specific RGB Values in the Same Row

분류에서Dev

ActionBar color change also ListView color

분류에서Dev

How to change default selection color of a ListView?

분류에서Dev

How to change the Foreground Color of ListView Selected Item

분류에서Dev

Change color of label in each repeatbox row

분류에서Dev

UITableView change background color of specific cell

분류에서Dev

How to find and change color of specific word in string

분류에서Dev

Change color of a specific region in eye image [Matlab]

분류에서Dev

Make particular listview row background different color - Android?

분류에서Dev

PulseAudio cannot change the sink for one specific program

분류에서Dev

How to make the listView row height change based on content?

분류에서Dev

ListBox specific row/item coloring Diffrent Color C# wpf

분류에서Dev

How to change to a specific color by its hex code in GIMP?

분류에서Dev

GTK2: How to change a specific color in a GTK theme

분류에서Dev

Use case to load json as one row instead of many, dataset specific

분류에서Dev

How to select one row with max(select field) and another (specific field)?

분류에서Dev

Check if a row in one DataFrame exist in another, BASED ON SPECIFIC COLUMNS ONLY

분류에서Dev

how to change one column and add other columns in a row by awk

분류에서Dev

How to change background of DataGrid row depending on value in one column

분류에서Dev

How to change cell value down one column into another but change the row value?

분류에서Dev

Select random row for each unique value in one specific column od fata frame

분류에서Dev

How to optimize query for optional input id (either one specific row or whole table)

분류에서Dev

How to optimize query for optional input id (either one specific row or whole table)

분류에서Dev

Put the result of one specific row of a JOIN statement into a record variable in PL/SQL

분류에서Dev

Change font in my listView

분류에서Dev

Changing color of items in ListView - Android

분류에서Dev

Counting the number of change from one value to another value in each pandas row and sum all counts

분류에서Dev

How to change button color

Related 관련 기사

  1. 1

    How do I permanently change the background color of a row in a Listview?

  2. 2

    Change Cell Color Based on Specific RGB Values in the Same Row

  3. 3

    ActionBar color change also ListView color

  4. 4

    How to change default selection color of a ListView?

  5. 5

    How to change the Foreground Color of ListView Selected Item

  6. 6

    Change color of label in each repeatbox row

  7. 7

    UITableView change background color of specific cell

  8. 8

    How to find and change color of specific word in string

  9. 9

    Change color of a specific region in eye image [Matlab]

  10. 10

    Make particular listview row background different color - Android?

  11. 11

    PulseAudio cannot change the sink for one specific program

  12. 12

    How to make the listView row height change based on content?

  13. 13

    ListBox specific row/item coloring Diffrent Color C# wpf

  14. 14

    How to change to a specific color by its hex code in GIMP?

  15. 15

    GTK2: How to change a specific color in a GTK theme

  16. 16

    Use case to load json as one row instead of many, dataset specific

  17. 17

    How to select one row with max(select field) and another (specific field)?

  18. 18

    Check if a row in one DataFrame exist in another, BASED ON SPECIFIC COLUMNS ONLY

  19. 19

    how to change one column and add other columns in a row by awk

  20. 20

    How to change background of DataGrid row depending on value in one column

  21. 21

    How to change cell value down one column into another but change the row value?

  22. 22

    Select random row for each unique value in one specific column od fata frame

  23. 23

    How to optimize query for optional input id (either one specific row or whole table)

  24. 24

    How to optimize query for optional input id (either one specific row or whole table)

  25. 25

    Put the result of one specific row of a JOIN statement into a record variable in PL/SQL

  26. 26

    Change font in my listView

  27. 27

    Changing color of items in ListView - Android

  28. 28

    Counting the number of change from one value to another value in each pandas row and sum all counts

  29. 29

    How to change button color

뜨겁다태그

보관