N
N
newdancer2017-02-09 12:34:05
Android
newdancer, 2017-02-09 12:34:05

How to set selection background when using MultiChoiceModeListener?

How to set selection background when using MultiChoiceModeListener? There is a listview with a custom adapter. In a snippet:

listCard.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        listCard.setItemsCanFocus(false);
        listCard.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                int selectedCount = listCard.getCheckedItemCount();
                setSubtitle(mode, selectedCount);
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflater = mode.getMenuInflater();
                inflater.inflate(R.menu.menu_main, menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {

            }
        });
    private void setSubtitle(ActionMode mode, int selectedCount) {
        switch (selectedCount) {
            case 0:
                mode.setSubtitle(null);
                break;
            default:
                mode.setTitle(String.valueOf(selectedCount));
                break;
        }
    }
</code lang="java">
пробовал сделать list selector
<code>    <ListView
        android:id="@+id/listCard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:listSelector="@drawable/list_selector"
        android:layout_marginTop="@dimen/fragment_mycard_rel_padding" /></code>
и drawable
<code lang="java">
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@android:color/holo_blue_light" android:state_selected="true"/>
    <item android:drawable="@android:color/transparent"/>

</selector>
</code>
но выделение item не отображается. Что не так? Или кроме как запоминать выбранные отдельные item и после в адаптере сверять не как?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question