Deselect selected item in ListView

后端 未结 8 756
天命终不由人
天命终不由人 2020-12-18 20:29

I use a ListView in my layout like this:

 

        
相关标签:
8条回答
  • 2020-12-18 20:31

    In your XML where you declare the ListView use:

    <ListView android:id="@+id/my_list" android:listSelector="#00000000" />
    
    0 讨论(0)
  • 2020-12-18 20:35

    Call requestLayout() on the ListView after clearChoices(). It will work.

    0 讨论(0)
  • 2020-12-18 20:39

    As @Muerte mentioned above, doing the following worked for me:

    myListView.clearChoices();
    myAdapter.notifyDataSetChanged();
    

    That seems like it would be better than redrawing the whole layout.

    0 讨论(0)
  • 2020-12-18 20:39

    try this

    Create your own selector xml file like this

    YourSelector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:state_enabled="false" android:state_focused="true"
            android:drawable="@drawable/item_disabled" />
      <item android:state_pressed="true"
            android:drawable="@drawable/item_pressed" />
      <item android:state_focused="true"
            android:drawable="@drawable/item_focused" />
    </selector>
    

    check out this link

    here

    0 讨论(0)
  • 2020-12-18 20:47

    Nothing of the solutions actually worked for me. My listview is for listing the searched items and has a provision to redo the search. On getting the result I added the following code snippet and it worked :)

    myAdapter.setSelectedIndex(-1);

    0 讨论(0)
  • 2020-12-18 20:50

    You can set a selector after click:

    <?xml version="1.0" encoding="utf-8"?>
    

    <item android:drawable="@drawable/transparent_white" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/transparent_white" android:state_focused="false" android:state_pressed="true"/>
    <item android:drawable="@drawable/transparent_white" android:state_focused="true"/>
    <item android:drawable="@drawable/transparent_white" android:state_focused="false"/>
    

    and the @drawable/transparent_white is #00ffffff

    0 讨论(0)
提交回复
热议问题