1

I have a problem of using selector that it does not work as what I expect. I wanna click on it then it gives me reaction and I select it(By long click but I probably do it through programmatic way) then it gives me another reaction. However, it reacts nothing in result....

reaction part:

 <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="10" android:padding="5dp" android:background="@drawable/border_bottom" > <LinearLayout android:layout_weight="9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/selector_row"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/grey" android:text="@string/tel"/> <TextView android:id="@+id/telText" android:layout_width="wrap_content" android:textSize="18sp" android:layout_height="wrap_content" android:text="@string/blank"/> </LinearLayout> <ImageButton android:layout_weight="1" android:id="@+id/tel_call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:src="@drawable/ic_action_call" android:background="@drawable/border_left"/> </TableRow> 

selector_row.xml:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@color/semitransparent_grey"></item> <item android:state_selected="true" android:drawable="@color/semitransparent_blue"></item> <item android:drawable="@color/transparent"></item> </selector> 
5
  • You miss a "normal" state Commented Jul 23, 2014 at 8:11
  • but I will do nothing in normal state Commented Jul 23, 2014 at 8:13
  • You MUST have a relaxed state. So it will return to THAT graphic, when not pressed/focused Commented Jul 23, 2014 at 8:14
  • how to set its normal state???I will not put any color on normal state. Can you post certain code??thx Commented Jul 23, 2014 at 8:16
  • I tried to put the selector to textview but when i press the text, it also reacts nothing Commented Jul 23, 2014 at 8:41

3 Answers 3

1

Thank you to all brothers trying hard to answer me. I have got the answer....just simply by setting android:clickable="true" at LinearLayout. Ha, it's silly.....

I remember dude who provide relating information but I ignored... sorry to him.

Sign up to request clarification or add additional context in comments.

Comments

1

Create an XML file and place it in the drawable folder. Open it and write the following code:

<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="YOUR IMAGE OR COLOR" android:state_pressed="true"/> <item android:drawable="YOUR IMAGE OR COLOR" android:state_selected="true"/> <item android:drawable="YOUR IMAGE OR COLOR" android:state_focused="true"/> </selector> 

Then in your main XML file, place android:background="@drawable/selector.xml"

4 Comments

android:state_normal<- no such option :O
I am just making a custom selector
place it in the drawable-hdpi folder It's not the right place. Put it in the /res/drawable folder, instead - since it's common to all screen densities.
No, it won't. but it's formally not correct. And it's a bad habit to put things in random places, just because it doesn't make any change
0

What are you expecting? A reaction only when it's clicked?

Try removing removing:

android:state_selected="true" 

Edit: This should be your selector:

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

What is the behaviour that you are experiencing?

Edit:

<LinearLayout android:layout_weight="9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/selector_row" android:duplicateParentState=true> 

I don't know if it actually solves the problem

7 Comments

Are you sure you don't have another color or background over your root layout? Can you post the whole xml layout resource?
So can you tell me what is the wrong behaviour that you are experiencing?
I click it, no response
Can you try adding duplicateParentState to true in the xml?
A layout property like android:layout_width
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.