Home > Mobile >  Android traverse a listview, change of each item in the listview a textview font color
Android traverse a listview, change of each item in the listview a textview font color

Time:10-27

After clicking on a button to change one of each item in the listview textview font color, great god told how to realize, this is what I write, but not achieve them, don't point don't change font color

CodePudding user response:

Adapter has a notifyDataSetChanged () method, and this way also is not very good ah, you can open a adapter set colors method,

CodePudding user response:

Adapter variables defined in the state, defining methods
Public void setState (int state) {
This. State=state
}

Item in getView assignment
If (state==1) {
TextView Settings to change the color of the
} else {
Initial color sets the default}

The button click add
{
If (adapter!=null) {
Adapter. SetState (1);
Adapter. NotifyDataSetChanged (); }
}

CodePudding user response:

Better control on the data source with a font color of the state through the notifyDataSetChanged update the font color of the item, but you can also through the for (I==0, iTextView TV=listView. GetChildAt (I) the findviewbyid (your id);
TV. SetTextColor (color)
}
  • Related