android-获取textview ID作为字符串 [英] android - get textview ID as string

查看:61
本文介绍了android-获取textview ID作为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML TextView布局:

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" />

具有绑定的onTouch()事件.
在onTouch()中,我需要获取textview的ID( txt0027_PDY911 )作为字符串,以便对其进行查询. getId()返回一个整数-如何获取字符串?

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?

谢谢

推荐答案

,您可以使用 getResources().getResourceEntryName(getId()) getResources().getResourceName(getId()).前者返回给定ID的条目名称.后者返回给定ID的全名.该名称是格式为"package:type/entry" 的单个字符串.

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".

这篇关于android-获取textview ID作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆