私のレイアウトでは、次のように定義しました。
<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で書かれているandroid:id="@+id/radio1"
どうすればそれが可能なのか誰か教えてもらえますか?
ベストアンサー1
アクティビティで次のことを試してください:
次のような文字列を取得します
radio1
:getResources().getResourceEntryName(int resid);
次のような文字列を取得します
com.sample.app:id/radio1
:getResources().getResourceName(int resid);
Kotlin の現在:
val name = v.context.resources.getResourceEntryName(v.id)