取消选择在ListView中选中的项目项目、ListView

2023-09-07 03:29:08 作者:神经科”常客

我用的ListView 在我的布局是这样的:

I use a ListView in my layout like this:

 <ListView android:id="@+id/list"
              android:layout_width="fill_parent"
              android:layout_gravity="center"
              android:layout_height="match_parent"
              android:layout_weight="0.7"
              android:layout_marginTop="5dp"
              android:orientation="vertical"
              android:layout_centerInParent="true"
              android:divider="@color/dark_grey"
              android:drawSelectorOnTop="false"
              android:focusable="true"
              android:layout_marginBottom="55dp"
              android:cacheColorHint="#00000000"
              android:listSelector="@color/light_grey"
              android:dividerHeight="1px" />

选择器的工作原理很大,但我怎么可以禁用选择?

The selector works great but how can I disable the selector?

我想:

listView.clearChoices();
listView.setSelected();
listView.setSelector();
...

和一些更多的东西,但没有任何工程。任何想法如何,我可以把我的选择的项目恢复正常?不能是复杂的,对吧?

and a few more things but nothing works. Any ideas how I can turn my selected item back to normal? Can't be that complicated, right?

编辑:我需要的程序化解决方案

I need a programmatical solution!

谢谢!

推荐答案

呼叫 requestLayout()的ListView clearChoices()。它将工作。