我有一个 ListView 并且可以选择一个元素(单选)。
选择某个项目时,如何为 ListView 的所有元素(可能至少是可见的)设置背景颜色?
adapter = new ArrayAdapter<Orderline>(activity, simple_list_item_single_choice, orderlines) {
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
...
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
convertView.setBackgroundColor(BLACK);
// so here currently selected element is set to BLACK, but also other elements have to be set to WHITE
}
});
return convertView;
}
}