Android: disable ListView selection

后端 未结 4 1496
北恋
北恋 2020-12-15 05:32

I have a listView that I re-display with the correct answer highlighted when the user selects an item. However, at that point I would like to disable selection of list view

相关标签:
4条回答
  • 2020-12-15 05:45

    The reason the scrolling is locked is because you are setting up at

    ListView
    

    I found a way to disable highlighting without locking the scroll. You need to set it up at ListAdapter as shown below:

    ArrayAdapter<String> myList = new ArrayAdapter<String>(this, R.layout.list_item, strText) {
               public boolean isEnabled(int position) 
                { 
                        return false; 
                } 
            };
    
    0 讨论(0)
  • 2020-12-15 05:46

    I just hid the selected item with this:

    listView.setSelector(new ColorDrawable(0));
    

    And then you show it again by restoring to whatever drawable it was using previously:

    wifiSsid.setSelector(R.drawable.listview_selector);
    
    0 讨论(0)
  • 2020-12-15 05:52

    I used android:choiceMode="none" as documented here.

    0 讨论(0)
  • 2020-12-15 06:09

    You can add attribute to Listview XML layout to disable multiple high light rows as

    android:listSelector="@android:color/transparent"               
    android:cacheColorHint="@android:color/transparent"
    
    0 讨论(0)
提交回复
热议问题