كيفية الحصول على Android String Array إذا كان لدي اسم Array في سلسلة أخرى
-
12-12-2019 - |
سؤال
لدي مشكلة، مشكلة فنية.لدي عرض قائمة، عندما أنقر فوق عنصر ما، أحصل على محتوى في هذا الموضع المحدد وأرسله إلى النشاط التالي من خلال "putExtra"
في النشاط التالي ما أفعله هو
String item;
Bundle extras = getIntent().getExtras();
if (extras != null) {
item = extras.getString("item");
}
الآن دعنا نقول هنا العنصر = "جافا"؛
الآن ما أريده هو termArray = getResources().getStringArray(R.array.Java);
لكنني لا أريد R.array.Java، أريد شيئًا مثل R.array.غرض
مصفوفات السلسلة في XML
<string-array name="Java">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
<string-array name="C">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
<string-array name="php">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
يمكنني القيام بهذه المهمة باستخدام IF-else ولكن لدي العديد من مصفوفات السلسلة، لذا لا يمكن استخدام IF-else
المحلول
حاول كـ:
String item;
Bundle extras = getIntent().getExtras();
if (extras != null) {
item = extras.getString("item");
int arryid = this.getResources().getIdentifier(item, "array",
this.getPackageName());
termsArray = this.getResources().getStringArray(arryid);
}
لا تنتمي إلى StackOverflow