I have same problem as Change the color of a specified item in a listview for android answered by Kartheek (Thank you) and adapted for testing as follows:
adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view1 = super.getView(position, convertView, parent);
// if (position % 2 == 0) { //Place the condition where you want
to change the item color.
testo = messaggi.get(position);
if(testo.substring(0,5).equals("27-09")){
view1.setBackgroundColor(Color.parseColor("#e0e0ef"));
} else {
//Setting to default color.
view1.setBackgroundColor(Color.WHITE);
}
return view1;
}
};
Question: I rather change font Color but view1.setTextColor(Color.parseColor("#E0E0EF"); does not seem to work;
Show Us db_msg this layout in that layout there is one TextView just get the name of that and replace with "tvIDFrom_db_msg_layout" this
adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view1 = super.getView(position, convertView, parent);
if (position % 2 == 0) { //Place the condition where you want to change the item color.
testo = messaggi.get(position);
TextView tvText = (TextView) view1.findViewById(R.id.tvIDFrom_db_msg_layout);
if(testo.substring(0,5).equals("27-09")){
tvText.setTextColor(Color.parseColor("#yourHexCode"));
} else {
//Setting to default color.
tvText.setTextColor(Color.WHITE);
}
return view1;
}
};