Saturday, 15 June 2013

java - android - Switching strings in a textView dynamically -



java - android - Switching strings in a textView dynamically -

i trying switch android:text of textview various strings dynamically retrieved strings.xml. when user presses button on grid, homecoming unique identifier. want utilize identifier dynamically load string pronoun textview.

gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { textview pronoun = (textview) findviewbyid(r.id.prounoun); chosen = ((textview) v).gettext(); //inserts identifier of button pressed local string chosen". pronoun.settext("r.string.pronoun_" + chosen); } }

when button 'a' pressed, 'chosen' holds letter 'a', when joining string naming format "pronoun_", resulting in "pronoun_a". intention phone call upon string @ location. in reality, text literally "r.string.pronoun_a" instead of retrieving actual string content of pronoun_a. if button 'b' pressed, want string content of 'pronoun_b' show in textview. new java, simply trying recreate technique learned in language. there way this?

use (with actual bundle name):

string reskey = "your.apps.package:string/pronoun_"+chosen; int resid = getresources().getidentifier(reskey, null, null); pronoun.settext(resid);

also see api docs.

note: and_dev mentioned, you'll have utilize activityname.this.getresources().

java android string

No comments:

Post a Comment