我正在做 android 并且想要一個一個地獲取 id 名稱,以便我可以以正確的順序顯示視圖上的資料,因此我將 id 保存為 ( selected1, selected2, selected3, ...)。實際上,我想在 MainActivity 中命名用戶在 SecondActivity 中選擇的所選專案,然后使用 Intent 在 MainActivity 中取回名稱。

但問題是我無法像 MainActivity 的 TextView 一樣動態呼叫 id 名稱
int counter = 1;
// to count till which view we put the data,
// numbering is also related to name of id's you can see in image
String str_count = Integer.toString(counter);
String selected = "selected";
String id_name = selected str_count;
// currently id_name = "selected1", I am going to increase this counter
// so next time we will get the next view
但它告訴我們用名稱創建新的 id id_name

uj5u.com熱心網友回復:
R.id.*實際上是一個整數值。你可以通過Resources#getIdentifier方法得到它。
TextView place = findViewById(
getResources().getIdentifier("selected" counter, "id", getPackageName())
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/353695.html
標籤:爪哇 安卓 xml 安卓工作室 android-标识符
