android 获取到id,一串数字,怎么反向知道他的命名?

如通过view.getid得到123123,那么通过这个123123得到对应的R.id.xx。

findViewById得到view,再取 getName

为什么要拿到R.id.xx,有什么作用

indViewById这个方法本身就是去找R文件了的控件id的。当你添加控件的时候,R文件里就会自动生成这样的一串数字 ,既索引坐标。如果id指向的string字符串,你可以这样,textview.setText(id),也就可以得到同样的值。

Resources类中的这个方法可以通过id获取到命名,不过获取到的命名格式是 package:type/entry;
一般获得context后,用getResources().getResourceName(int id), 返回字符串

/**
* Return the full name for a given resource identifier. This name is
* a single string of the form "package:type/entry".
*
* @param resid The resource identifier whose name is to be retrieved.
*
* @return A string holding the name of the resource.
*
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @see #getResourcePackageName
* @see #getResourceTypeName
* @see #getResourceEntryName
*/
public String getResourceName(@AnyRes int resid) throws NotFoundException {
return mResourcesImpl.getResourceName(resid);
}

这是典型的Java反射呀