2011-08-22 6 views
3

AlertDialog가 두 번 연속 표시됩니다. Nexus S에서는 예상대로 모든 것이 작동하지만 두 번째로 대화 상자가 표시되면 Wildfire에서 키보드가 사라집니다.Android : EditText가있는 AlertDialog가 자동으로 키보드를 표시하지 않습니다.

생성자에 중단 점을 넣고 거기에서 계속할 때 키보드가 표시되기 때문에 약간의 타이밍 문제 여야합니다. 어쩌면 onFocusChange가 키보드를 표시해야하는 적절한 장소가 아닐 수도 있습니다.

내가 그것을 어떻게 를 해결할 수 있습니까? 이 문제의 원인을 찾기 위해 무엇을 찾겠습니까?

/** 
* Show a dialog asking the user to confirm the PIN. 
*/ 
private static abstract class PinConfirmationDialog extends AlertDialog { 

    protected PinConfirmationDialog(Context context, final int titleResource) { 
     super(context); 
     setTitle(titleResource); 

     // Set an EditText view to get user input 
     final EditText input = new EditText(context); 
     InputFilter[] FilterArray = new InputFilter[1]; 
     FilterArray[0] = new InputFilter.LengthFilter(4); 
     input.setFilters(FilterArray); 
     input.setKeyListener(DigitsKeyListener.getInstance(false,true)); 
     input.setInputType(InputType.TYPE_CLASS_NUMBER 
       | 16 /*InputType.TYPE_NUMBER_VARIATION_PASSWORD Since: API Level 11*/); 
     input.setTransformationMethod(new PasswordTransformationMethod()); 
     setView(input); 

     setButton(context.getString(R.string.okay_action), new OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       onOkButtonClicked(input.getText().toString()); 
      } 
     }); 
     setButton2(context.getString(R.string.cancel_action), new OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       onCancelButtonClicked(); 
      } 
     }); 

     input.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 
       if (hasFocus) { 
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
       } 
      } 
     }); 
    } 

    /** 
    * OK Button was pressed 
    * @param pinCode The code the user has entered 
    */ 
    abstract void onOkButtonClicked(String pinCode); 

    /** 
    * Override method if needed 
    */ 
    protected void onCancelButtonClicked() { 
    } 
} 
+0

http://stackoverflow.com/questions/2403632/android-show-soft-keyboard-automatically-when-focus-is-on-an-edittext 참조 –

답변

0

이 시도 :

// Setting of the Keyboard 
InputMethodManager imm = (InputMethodManager) 
getSystemService(Context.INPUT_METHOD_SERVICE); 
// For SHOW_FORCED 
imm.showSoftInput (YOUEDITTEXT, InputMethodManager.SHOW_FORCED); 

는 당신 도움이되기를 바랍니다! 당신이 시도 할 수

+0

불행히도 효과가 없습니다. –

0

,

editText.setFocusable(true); 
requestfocus(); 
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0); 
관련 문제