I'm trying to dynamically change the text and the title of an Activity Main1 which extended to Text1 where the titles and textes, I did this code but never worked:
public class MainText1 extends Text {
String
tx1=text1,tx2=text2,tx3=text3,
tl1=title1, tl2=title2,tl3=title3,tl,tx;
num = Integer.parseInt(getIntent().getStringExtra("somekey1")); // this data is coming from the menu, it depends on which button is clicked
tl="tl"+num;
tx="tx"+num;
stringId1 = getApplicationContext().getResources().getIdentifier(tl, "string", getPackageName());
stringId2 = getApplicationContext().getResources().getIdentifier(tx, "string", getPackageName());
if (stringId1 > 0) {
title=getApplicationContext().getResources().getString(stringId1);
text2=getApplicationContext().getResources().getString(stringId2);
}
else
{
title=Integer.toString(stringId1);
text2=Integer.toString(stringId2);
}
text1 = "<font color=#000080><b>" + title + "</b></font>";
t1.setText(Html.fromHtml(text1));
t2.setText(Html.fromHtml(text2));
the problem is that stringId1 and stringId2 giving 0 value.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…