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 your ListView in your layout-xml.
I think you are using a custom adapter and so you can use the method isEnabled(int position) of the baseadapter class and make the item that is clicked enabled and the remaining disabled. But i wonder what's the reason for making the other items unfit for selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With