0

创建布局时,您为视图定义一个 id,如下所示:

<ImageView
   android:id="@+id/myImage"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:src="@drawable/main01" />

在您的代码中,您有:

ImageView img = (ImageView) findViewById(R.id.myImage);

现在你有了img.

如何将img("myImage")的 id作为字符串获取?我需要这样的东西:

String strId = getStringId(img);
// now strId is "myImage"
4

2 回答 2

2

试试这个。

Log.i("============ Id","::"+getResources().getResourceEntryName(img.getId()));

输出:============ Id :: myImage

于 2012-09-25T10:21:03.223 回答
0

这是你要找的吗?

String value = getResources().getString(R.id.myImage);
于 2012-09-25T10:20:21.690 回答