Android ListView StateListDrawable在Choice Mode Multi Modal&选择模式单一

时间:2015-08-02 15:18:57

标签: android android-listview android-drawable statelistdrawable

我的应用中有一个非常简单的列表视图。我允许用户点击列表视图中调用新活动的任何项目,以显示该项目的其他信息。这在选择模式单一中发生。我还允许用户长按任何我提供上下文菜单的项目。该上下文菜单中的一个选项是Multi Select。它使用户能够选择多个项目并一次性删除它们。在这种情况下,我切换到CHOICE_MODE_MULTIPLE_MODAL。

要更改所选项目的背景,我在listview项目布局xml中使用background drawable指向选择器。如下所示:

列出项目布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/multi_background"
        android:orientation="horizontal"
        android:id="@+id/foo_bar">
    <TextView android:id="@+id/foo_bar_desc" 
        android:layout_width="match_parent"
        android:textSize="22sp"
        android:layout_height="wrap_content"/>
</LinearLayout>

Drawable multi_background:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_activated="true" android:drawable="@color/DarkBlue"></item>
</selector>

在多选模式下选择多个项目时,此工作正常并提供所需的结果。但是,一旦我在listview上调用multi select选项后,即使我点击列表项查看其他信息,在切换到活动以显示其他信息之前,背景会变为蓝色仅一秒钟。但是,如果我在进入应用程序后点击列表项而不进入多选选项,行为就可以了。点击项目的背景将更改为Holo主题的默认深灰色,并且显示其他信息的活动将在没有一秒延迟的情况下开始。

我不做我应该做的事情吗?任何帮助将不胜感激。

0 个答案:

没有答案