I have a listview and a button outside listview. I want the user to select an item in listview and then when clicking on button I wanna get the selected item of list view. I have set choiceMode to single choice on listview, but when I try getselecteditem it returns null. How should I get the selected Item?
thanks.
This is an old question, so probably not that relevant anymore. But here's what's the problem:
The ListView doesn't store selected item position when you just set the choice mode. It stores the checked item position.
In short, you would use something like:
int pos = listView.getCheckedItemPosition();
myObject = (MyObject) listView.getAdapter().getItem(pos);
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