lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

setChoiceMode(TwoWayView.ChoiceMode.SINGLE) doesn't work #40

Open AntonHolovin opened 10 years ago

AntonHolovin commented 10 years ago

I try to set ChoiceMode to ChoiceMode.SINGLE. I want to change background for custom item view when it selected and I wrote selector that checks android:state_activated="true". It doesn't work. The item gets default background every time.

The part of the custom item:

<TextView
            android:id="@+id/text1"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/item_section_background_selector"
            android:textSize="12sp"
            android:gravity="center_horizontal|center_vertical"
            android:textColor="@android:color/black"
            android:text="Example"/>

Selector:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:drawable="@android:color/transparent"/>
    <item android:drawable="@drawable/section_background"/>
</selector>
AntonHolovin commented 10 years ago

This problem can be solved by this example, but it's worse.

twoWayView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            private TextView mLastClickedTextView;

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                if(mLastClickedTextView != null) {
                    mLastClickedTextView.setBackgroundResource(R.drawable.section_background);
                }

                TextView textView = (TextView) view.findViewById(R.id.text_section_name);
                textView.setBackgroundResource(android.R.color.transparent);

                mLastClickedTextView = textView;
            }
        });