setMultiChoiceModeListener未在列表视图中激活

时间:2015-06-02 11:54:46

标签: android listview multiple-select

在我的应用程序中,我希望用户选择多个列表项。因为我已经使用了choiceMode = Multiple.But当我尝试选择一件事时其他选择已经消失。而且我的listView.setMultiChoiceModeListener()也没有触发达

代码

lvCategories = (ListView) findViewById(R.id.lv_search_list);
        lvCategories.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

        rlLoc = (RelativeLayout) findViewById(R.id.rl_search_loc);

        arrCategories = getResources().getStringArray(R.array.search_categories);
        adapter = new SearchCategoriesAdapter(contextActivity, getListData());

        lvCategories.setAdapter(adapter);

        //lvCategories.setItemsCanFocus(false);

        lvCategories.setMultiChoiceModeListener(this); 

XML

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:layout_weight="3"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView5"
            style="@style/text_style"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#50FFFFFF"
            android:gravity="center|start"
            android:hint="select category"
            android:paddingLeft="15dp"
            android:textSize="20sp" />

        <ListView
            android:id="@+id/lv_search_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="1dp"
            android:layout_weight="1"
            android:listSelector="@android:drawable/list_selector_background"
            android:divider="#7c7885"
            android:dividerHeight="1dp" />
    </LinearLayout>

如果我从列表中选择一个项目,则表示未选择该项目。

0 个答案:

没有答案