在我的布局中,我已经定义了类似的东西.
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dnt want this text" />
Run Code Online (Sandbox Code Playgroud)
假设活动中的某些函数返回此id(radioButton的id).现在我想从这个id 得到这个文本radio1.总之,我想要检索写入的文本radio1android:id="@+id/radio1"
有人能告诉我怎么可能?
Shu*_*ayu 335
在您的活动中,试试这些:
得到字符串radio1:
getResources().getResourceEntryName(int resid);
Run Code Online (Sandbox Code Playgroud)得到字符串com.sample.app:id/radio1:
getResources().getResourceName(int resid);
Run Code Online (Sandbox Code Playgroud)在Kotlin Now:
val name = v.context.resources.getResourceEntryName(v.id)
Run Code Online (Sandbox Code Playgroud)
你有ID("长"型)从您要访问单选按钮ID 编号(名称),这是收音机1.你用它
getResources().getResourceEntryName(id);
Run Code Online (Sandbox Code Playgroud)
在上面使用你可以得到单选按钮的名称,即radio1.这里参数id是你有的(长类型).试试这个它会帮助你100%.
小智 5
科特林:
val name = v.context.resources.getResourceEntryName(v.id)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70793 次 |
| 最近记录: |