在列表视图中选择多个项目,并更改所选项目的背景颜色
问题描述:
我坚持了1件事,我想这样的一个观点:
Hey I am stuck with 1 thing that I want a view like this :
在ListView在那里我可以选择多个项目和任何项目我可以选择我可以改变颜色backgrond并添加该项目入数组列表,这样我可以进一步利用它..
where in a listview I can select multiple items and whichever item I can select I can change the backgrond color and also add that item into the arraylist so that I can use it further..
请人帮我在这??
编辑:
我使用它是这样的:
ArrayAdapter<String> part_list_adapter=new ArrayAdapter<String>(AssetSearch.this, R.layout.part_list,R.id.label,part_array_list);
PartNumber_List.setAdapter(part_list_adapter);
PartNumber_List.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
String item = (String)PartNumber_List.getItemAtPosition(position);
Log.i("Item", item);
v.setBackgroundColor(R.color.result_image_border);
}
});
在这里,在一个记录它显示我的项目点击only..but改变了2项...
Here in a log it is displaying me the item clicked only..but changes color of 2 items...
答
尝试这样的..
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
String item = (String) getListAdapter().getItem(position);
boolean blnFound = yourarrayList.contains(item);
if(blnFound=true){
yourarraylist.remove(item);
v.setBackgroundColor(R.color.somecolourtoindicate notselected);
}
else{
yourarraylist.add(item);
v.setBackgroundColor(R.color.somecolourtoindicate itemselected);
}
yourarraylist.add((String) getListAdapter().getItem(position);)
}