2012-10-20 6 views
0

안드로이드 텍스트보기의 이름을 어떻게 동적으로 바꿀 수 있습니까? 이름이 이미 작성된 텍스트 뷰와 관련이 있어야 편집 텍스트 응답이 제공되는 것에 따라 이름을 지정하고 싶습니다. 인스턴스 이름이 이미 xml의 res id로 지정되어 있습니다. 예 최종 TextView 이름 a = (TextView) this.findViewById (R.id.Texti5);이름 바꾸기 android textview

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; 




    } }); 

답변

1

아마도 비슷한 목표를 달성 할 수있는 방법은 if ​​문에 따라 태그를 textview에 부여하는 것입니다.

textview1.setTag("a"); 

그런 다음 다시 같은 태그를 얻을 수 있습니다 :

if (textview1.getTag() == "a") { 
// do something 
} 

이, 적어도, 당신이 제안하는 것보다 더 많은 기존의 것입니다.