Reputation: 2461
I have a ListView
which is correctly filled and it displays all its items. I was wondering how could I change the color of one of its rows (index = 0). I was trying to use the ListView
and reaching its child using listView.getChildAt(0)
but I do not see any method to change the color of the text (just for the background)
Just in case is needed I post the method that I use to update the ListView
String[] aux = new String[namesList.size()];
namesList.toArray(aux);
arrayAdapter = new ArrayAdapter<>(getActivity(), R.layout.row, aux);
listView.setAdapter(arrayAdapter);
if(from)
listView_address.getChildAt(0) // Not a method which I could use
setSelectNameListeners();
Upvotes: 0
Views: 498
Reputation: 971
Yo can try this:
String[] aux = new String[namesList.size()];
namesList.toArray(aux);
arrayAdapter = new ArrayAdapter<>(getActivity(), R.layout.row, aux){
@Override
public View getView(int position, View convertView, ViewGroup parent){
if(position == 0){
// Get the Item from ListView
View view = super.getView(position, convertView, parent);
// Initialize a TextView for ListView each Item
TextView tv = (TextView) view.findViewById(android.R.id.text1);
// Set the text color of TextView (ListView Item)
tv.setTextColor(Color.RED);
// Generate ListView Item using TextView
return view;
}
}
};
listView.setAdapter(arrayAdapter);
Upvotes: 1
Reputation: 303
You cannot change the color of a String, however you can change color of a textview. A String only tells what to display, a textView will be responsible for how to display the information, now to change the color of the text you'll need a custom adapter and make that adapter return you the items, you get the 1st item and change it's color.
Upvotes: 2