2013-07-19 1 views
1

수정해야하는 일부 비난 된 코드가 있습니다. 대화 상자 (showdialog)가 닫히고 나면 edittext에 초점을 맞추고 텍스트를 선택하고 키보드를 올리 길 원합니다. 이것은이 코드에서 발생하지 않습니다.DismissDialog 후에 EditText에 포커스를 설정하십시오.

이 코드를 사용하면 포커스는 없지만 텍스트가 선택됩니다.

... 
alert.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 
        EditText txtE = (EditText) findViewById(R.id.ORE); 
        dismissDialog(DIALOG_NO_E); 
        txtE.selectAll(); 
        txtE.requestFocus();       
       } 
      }); 
... 

제안 사항?

+0

먼저 대화 상자를 닫은 다음 txtE.requestFocus(); – TheFlash

+0

단순히'RequestFocus()'를 사용하십시오. –

+0

주위를 움직이기 위해 노력했지만. – Johan

답변

1

requestfocus 이후에 추가하면 작동합니다. 그러나 그것은 옳다고 느끼지 않습니다.

txtE.postDelayed(new Runnable() { 
         public void run() { 
          android.view.inputmethod.InputMethodManager keyboard = (android.view.inputmethod.InputMethodManager) getSystemService(android.content.Context.INPUT_METHOD_SERVICE); 
          keyboard.showSoftInput(txtE, 0); 
         } 
        }, 200); 

최종 결과

... 
alert.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 

        dismissDialog(DIALOG_NO_E); 
        txtE.selectAll(); 
        txtE.requestFocus();       
       } 
      }); 
txtE.postDelayed(new Runnable() { 
          public void run() { 
           android.view.inputmethod.InputMethodManager keyboard = (android.view.inputmethod.InputMethodManager) getSystemService(android.content.Context.INPUT_METHOD_SERVICE); 
           keyboard.showSoftInput(txtE, 0); 
          } 
         }, 200); 
... 

누군가가 내가 이런 식으로 할 필요가 왜 더 나은 솔루션 또는 답변이 있다면, 난 당신에게 대답 월요일에 최신의 포인트를 줄 것이다.

이 작업을 수행하려면 생성자에서 초기화 된 정적 변수로 txtE을 만들어야했습니다. 그 didnt는 나의 영혼에서 전혀 기분이 좋지 않다. 그래서, 누군가가 더 좋은 생각을 가지고 있다면, 말해라.

관련 문제