2014-11-07 2 views
-2
당신이의 setText로 텍스트를 변경 한 후 화면을 업데이트하려면 어떻게

..android에서 setText로 텍스트를 변경 한 후 어떻게 화면을 업데이트합니까?

코드 :

TextView settings_text = (TextView) findViewById(R.id.tv_settings); 
     settings_text.setText(Strings.SETTINGS);  


TextView terms_text = (TextView) findViewById(R.id.tv_terms); 
     terms_text.setText(Strings.TERMS); 

TextView about_text = (TextView) findViewById(R.id.tv_aboutus); 
     about_text.setText(Strings.ABOUT); 

Intent intent = new Intent(Language.this,MenuScreen.class);  
      startActivity(intent); 
    finish(); 

문제 : 이 후 값이 화면에 반영되지 않습니다

나 제안 ..Thank 당신

+0

간단한 startActivity() 및 finsih() 코드를 제거하면 값이 변경되는지 여부를 알 수 있습니다. –

+0

이 텍스트를 설정 한 활동을 마치고 있습니다. – jvrodrigues

+0

실제 문제는 다음과 같습니다. 처음 시간은 값이 반영되지 않고 두 번째 시간부터 적용됩니다. 즉, 다른 화면으로 이동하여 다시 수정 된 화면으로 이동하는 경우입니다. .. 이번에는 내용이 수정되고 있습니다. –

답변

0

지연 두 번째 활동 시작 :

import android.os.Handler; 

new Handler().postDelayed(new Runnable(){ 
    public void run(){ 
     Intent intent = new Intent(Language.this,MenuScreen.class);  
     startActivity(intent); 
    } 
},5000); // 5000 is represent time to delay execute code under run(). 
을 경고 대화

TextView terms_text = (TextView) findViewById(R.id.tv_terms); 
    terms_text.setText(Strings.TERMS); 

텍스트 뷰 about_text = (텍스트 뷰) findViewById를 (R.id.tv_aboutus)를 사용하여

; :

+0

사실 나는 당신의 첫 번째 의견을 바탕으로 다른 방식으로 작업을 수행했습니다. 텍스트 값을 설정하면 화면을 기본 화면으로 리디렉션하고 경고 메시지를 보내고 값 변경이 발생합니다 .. –

+0

then good 운. –

+0

굉장한 친구. 당신의 대답은 작동합니다. 그러나 문제는 지연과 관련이 있습니다. 그러나 문제는 아닙니다 !! –

0

첫번째 방법 about_text.setText (Strings.ABOUT);

TextView contactus_text = (TextView) findViewById(R.id.tv_contactus); 
contactus_text.setText(Strings.CONTACT_US); 

AlertDialog.Builder alertDialog = new AlertDialog.Builder (Language.this);

alertDialog.setTitle("Alert"); 
    alertDialog.setMessage("Language changed successfully"); 
    alertDialog.setCancelable(false); 
    alertDialog.setPositiveButton("Continue",new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
        Intent intent = new Intent(Language.this,MenuScreen.class);                startActivity(intent); 
          finish(); 

} 

});

alertDialog.show();

두번째 방식 : POSTDELAYED 방법을 사용

텍스트 뷰의 terms_text = (텍스트 뷰) findViewById를 (R.id.tv_terms); terms_text.setText (Strings.TERMS);

TextView about_text = (TextView) findViewById (R.id.tv_aboutus); about_text.setText (Strings.ABOUT);

TextView contactus_text = (TextView) findViewById(R.id.tv_contactus); 
contactus_text.setText(Strings.CONTACT_US); 

new Handler().postDelayed(new Runnable(){ 
     public void run(){ 
       Intent intent = new Intent(Language.this,MenuScreen.class);  
              startActivity(intent); 
             } 
            },100); 
관련 문제