0

I have selector line on my textView.

selector.xml :

  <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--<item android:drawable="@drawable/select_white" android:state_activated="true"/>-->
    <item android:drawable="@drawable/select_white" android:state_pressed="true"/>
    <item android:drawable="@drawable/select_white" android:state_selected="true"/>
    <item android:drawable="@drawable/select_white" android:state_focused="true"/>
    <item android:drawable="@drawable/select_none"/>
</selector>

and i set as background for my textView :

                   <TextView
                    android:id="@+id/displayPlace"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:clickable="true"
                    android:text="@string/place"
                    android:textColor="@color/white"
                    android:background="@drawable/selector"
                    android:textSize="@dimen/text_main"/>

when i click on text view selector appeared fine, but i have to do action on my click, so to do my action it's rquired to click twice, I have tried to remove android:focusableInTouchMode="true" line but it make selector visible for a bit of second and gone.

How i can do action on first click with selector ?

My on Click :

place.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fragment = new PlaceFragment();
            replaceFragment(fragment);
            Fragment fragment2 = getFragmentManager().findFragmentByTag(TAG_FRAGMENT);
            if (fragment2 != null)
                getFragmentManager().beginTransaction().remove(fragment2).commit();
        }
    });

2 Answers2

1

Just try to use setOnFocusChangeListener instead of setOnClickListener.

0

There are two way you can use double click

1) Using timer in OnClickListener https://gist.github.com/srix55/ec64d2f6a371c80bbbc4
2) Using GestureDetector onDoubleTap listnerer https://stackoverflow.com/a/13531025/4741746 and https://stackoverflow.com/a/21449185/4741746

Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55