How to get the selected item from ListView?

前端 未结 9 731
我寻月下人不归
我寻月下人不归 2020-11-29 03:26

in my Android app I have created a ListView component called myList, and filled it with objects of my own custom type:

class MyClass{

    private String di         


        
9条回答
  •  余生分开走
    2020-11-29 03:54

    By default, when you click on a ListView item it doesn't change its state to "selected". So, when the event fires and you do:

    myList.getSelectedItem();
    

    The method doesn't have anything to return. What you have to do is to use the position and obtain the underlying object by doing:

    myList.getItemAtPosition(position);
    

提交回复
热议问题