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. returns an integer - how can I get the string? 返回一个整数-如何获取字符串?
Thanks
you can use getResources().getResourceEntryName(getId())
or getResources(). getResourceName(getId())
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"
.
you can try :
text.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch (View v, MotionEvent event) {
...
String id= v.getResources().getResourceName(v.getId());
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.