I have the same problem as discussed on Handling click events on a drawable within an EditText, but I use TextView
instead of EditText
. When I click on the TextView
, the method onTouchEvent(MotionEvent event)
is called. Is it possible to handle a click only on the icon?
Asked
Active
Viewed 2,489 times
0

Community
- 1
- 1

Maksim Dmitriev
- 5,985
- 12
- 73
- 138
-
1you can use TouchDelegate.... – Anand Tiwari Nov 30 '12 at 07:57
-
@AnandTiwari, I found [this code](https://github.com/cyrilmottier/ListViewTipsAndTricks) – Maksim Dmitriev Nov 08 '13 at 08:33
2 Answers
0
I think the idea is pretty much the same as described here: use the event coordinates and determine if they are within the drawable's bounds. If they are, perform your action. I don't think there are any major differences between TextView
and EditText
in this respect.

Community
- 1
- 1

Andrii Chernenko
- 9,873
- 7
- 71
- 89
-
Thank you for the link, but I have another [solution](http://stackoverflow.com/a/19834049/1065835) – Maksim Dmitriev Nov 07 '13 at 10:54
0
I think that it would be a better idea to use a TextView
and an ImageView
. Of course, it leads to a more complex layout structure, but I'd prefer two widgets in an XML file rather than too much Java code dealing with the widgets.
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/iv"
android:text="@string/long_text"
android:textSize="22sp" />
<ImageView
android:id="@id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/app_name"
android:src="@drawable/btn_go" />

Community
- 1
- 1

Maksim Dmitriev
- 5,985
- 12
- 73
- 138