Why is my onItemSelectedListener not called in a ListView?

后端 未结 3 1316
暖寄归人
暖寄归人 2020-12-15 02:45

I\'m using a ListView that is setup like this:



        
相关标签:
3条回答
  • 2020-12-15 02:56

    The OnItemSelectedListener listens for list item selections and not list item clicks.

    A selection in this case could be seen as moving the focus on this item with the device's trackpad.

    To get the wanted behavior one must use the OnItemClickListener.

    0 讨论(0)
  • 2020-12-15 03:05

    It's because you happen to be testing with your fingers on a touch-enabled device. In touch mode, there is no focus and no selection. UIs that need selection should use a different type of widget, such as radio buttons.

    0 讨论(0)
  • 2020-12-15 03:19

    At first,you should set ChoiceMode,and then,in ListView,there will not accept the selected event because setOnItemSelectedListener registed in AdapterView,and callback in method handleDataChanged(),but class AbsListView override this method and never callback OnItemSelectedListener

    you can get the seletedItem by this method in setOnItemClickListener

         mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("TAG", "onItemClick: " + position);
                SparseBooleanArray positions = mListView.getCheckedItemPositions();
                Log.e("TAG", "onItemSelected: " + positions.toString());
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题