Reputation: 139
How can I rename android text view dynamically? I want to assign a name depending on what edit text answer is given the name has to relate to a already created textview. For instance name a is already assigned a res id in the xml example final TextView name a = (TextView) this.findViewById(R.id.Texti5);
editext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode==KeyEvent.KEYCODE_ENTER) {
if("test1".equalsIgnoreCase(anstext.getText().toString())) {
// Here i want to give textview1 the 'name a'
}}
else
if("test2".equalsIgnoreCase(editext.getText().toString())) {
// Here i want to give textview1 the 'name b'
}
if("test5".equalsIgnoreCase(editext.getText().toString())) {
// Here i want to give textview1 the 'name c'
}
if("test7".equalsIgnoreCase(editext.getText().toString())) {
// Here i want to give textview1 the 'name d'
}
if (editext.getText().toString() != null){
testwrong.seText("wrong"); }
}
// here i want to see what name is given and give the name to textview1 so i can
perform click on that textview as it is clickable
textview1.performClck();
return true;
} });
Upvotes: 0
Views: 879
Reputation: 5636
Perhaps a method that might achieve a similar goal is to give the textview a tag depending on your if statements.
textview1.setTag("a");
Then you can get the tag back like:
if (textview1.getTag() == "a") {
// do something
}
this would, at the very least, be more conventional than what you are proposing.
Upvotes: 1