创建布局时,您为视图定义一个 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"