I list site addresses with Android listview.I tried for hours, but I couldn't find a solution.
for example
http://site .com
http://site2 .com
http://site3 .com
http://site4 .com
if have http://site3.com
in listView
i want to change the color of this line.
final ListAdapter adapter = new SimpleAdapter(
MainActivity.this,
resultsdatalist,
R.layout.list_item,
new String[]{"resultid", "result"},
new int[]{R.id.resultid, R.id.result}) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
};
lv.setAdapter(adapter);
Try this:
@Override
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if(getItem(position).equals("site3.com"))
{
// do something change color
view.setBackgroundColor (Color.RED); // some color
}
else
{
// default state
view.setBackgroundColor (Color.WHITE); // default coloe
}
return view;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.