i have a ListView and i want to select one item from the list and change the background color to gray. Currently, if i select one from the list, i can also select another… i want to limit my selection to 1 and when i select an item i will not be able to select another item.
here’s my code:
myadapter = new MyAdapter(Main.this, object_list);
mylist.setAdapter(myadapter);
mylist.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
view.setBackgroundColor(Color.LTGRAY);
}
});
Add
android:choiceMode="singleChoice"to yourListViewin your layout-xml.