How to get the selected item from ListView?

前端 未结 9 719
我寻月下人不归
我寻月下人不归 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条回答
  •  猫巷女王i
    2020-11-29 03:56

    You are implementing the Click Handler rather than Select Handler. A List by default doesn't suppose to have selection.

    What you should change, in your above example, is to

    public void onItemClick(AdapterView adapter, View v, int position, long id) {
        MyClass item = (MyClass) adapter.getItem(position);
    }
    

提交回复
热议问题