Android ListView多选模式保持行高亮显示



我希望有一个列表视图,它可以突出显示单击的项目,现在当你单击一个项目时,它会被突出显示,但一次只能突出显示一个,即使multipleChoice设置为

列表视图

<ListView
    android:id="@+id/right_drawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:choiceMode="multipleChoice"
    android:listSelector="@drawable/row_background_selector"
    android:drawSelectorOnTop="false"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#09ffffff"/>

row_background_selector

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:exitFadeDuration="@android:integer/config_mediumAnimTime">
    <item android:drawable="@android:color/darker_gray" android:state_pressed="true"/>
    <item android:drawable="@android:color/darker_gray" android:state_selected="true"/>
    <item android:drawable="@android:color/background_light" android:state_activated="true"/>
    <item android:drawable="@android:color/black"/>
</selector>

这样做可能吗?

我使用了一个上下文操作栏,这里有一个例子http://developer.android.com/intl/es/guide/topics/ui/menus.html#CAB

是的,这是可能的,但不是多选模式

mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mListView.setMultiChoiceModeListener(new MultiChoiceCallback());

其中MultiChoiceCallback实现AbsListView.MultiChoiceModeListener

private class MultiChoiceCallback implements AbsListView.MultiChoiceModeListener { ... }

阅读更多关于ActionMode的信息以使用它。

最新更新