Reputation: 335
I have the following XML TextView layout:
<TextView
android:layout_width="100dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:id="@+id/txt0027_PDY911"
android:tag="canPlot"
style="@style/STD_Block_BEL.FieldLabel"
android:text="0.00" />
which has a onTouch() event bound.
In the onTouch() I need to obtain the textview's id (txt0027_PDY911) as string in order to run a query with it.
getId() returns an integer - how can I get the string?
Thanks
Upvotes: 3
Views: 3036
Reputation: 1270
you can try :
text.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch (View v, MotionEvent event) {
...
String id= v.getResources().getResourceName(v.getId());
}
});
Upvotes: 1
Reputation: 157487
you can use getResources().getResourceEntryName(getId())
or getResources(). getResourceName(getId())
. The former returns the entry name for a given id. The latter returns the full name for a given id. This name is a single string of the form "package:type/entry"
.
Upvotes: 6