I have a android file explorer application and I need to highlight the selected item. I could select touched items using v.setBackgroundColor() method inside onListItemClick(). But when I touch another file/folder still previous one highlighted. I need only current touched item display as selected. How to do this?
问问题
75 次
1 回答
0
不完美但效果很好
遍历列表的所有项目并尝试这样的事情
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
for (int i = 0; i < arg0.getCount(); i++) {
View view = arg0.getChildAt(i);
if (i == arg2) {
view.setBackgroundColor(Color.RED);
} else {
view.setBackgroundColor(Color.GREEN);
}
}
}
});
于 2014-01-07T03:54:22.887 回答