如何获得资源名称的资源ID资源、如何获得、名称、ID

2023-09-11 12:19:56 作者:遗忘便是幸福﹌

在我的布局我已经定义了这样的事情。

In my layout i have defined something like this .

            <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Dnt want this text" />

假设在活动的一些函数返回我这个ID(单选按钮的ID)。现在,我想这个文本的收音机1 此ID。 总之我想要检索的文本收音机1 写在机器人:ID =@ + ID /收音机1

有谁能告诉我,怎么可能?

Can somebody tell me how is it possible ?

推荐答案

在你的活动,请尝试以下

In your Activity, try the following

getResources()getResourceEntryName(INT渣油);

getResources().getResourceEntryName(int resid);

getResources()getResourceName(INT渣油);

getResources().getResourceName(int resid);

您将preFER第一个我想。

You'll prefer the first one I guess.