我正在通过putExtra()和getExtra()从一个活动向另一个活动传递值,并获得如下值:
从活动1:
intent = new Intent(this, blankScrollActivity.class);
intent.putExtra("alphabets", "a");
在活动2上接收:blankScrollActivity.class
Bundle extras = getIntent().getExtras();
String varName = extras.getString("alphabets");
TextView textView = (TextView) findViewByid(R.id.blankTextView);
字符串资源MyString.xml:
<string name="a">My Example 1</string>
<string name="b">My Example 2</string>
我想动态获取字符串的值以分配textView。
Bundle extras = getIntent().getExtras();
String varName = extras.getString("alphabets");
int resId = getResources().getIdentifier(varName , "string", getPackageName());
String data = getResources().getString(resId);
这样,您将基于从第一个Activity发送的值获得所需的String资源String
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句