2012-11-21 79 views
0

在我的應用程序中,我有EditText對話框。我想要獲得編輯框automaticaly.i.e的keyboad,當顯示對話框時應該顯示鍵盤。有沒有辦法顯示鍵盤而不觸及EditText。在對話框中的Android EditText

我加入對話代碼

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle(APP_NAME); 
    builder.setMessage(message); 
    // Use an EditText view to get user input. 
    final EditText inputDevice = new EditText(this); 
    final EditText inputTester = new EditText(this); 

    if (id == DLG_ID_TESTER) { 
     inputTester.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); 
     // inputTester.setThreshold(1); 
     inputTester.setSelectAllOnFocus(true); 
     inputTester.requestFocus(); 
     inputTester.setId(TXT_ID); 
     builder.setView(inputTester); 
    } else { 
     inputDevice.setId(TXT_ID); 
     inputDevice.setSelectAllOnFocus(true); 
     builder.setView(inputDevice); 
    } 
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 

     @Override 
     public void onClick(DialogInterface dialog, int whichButton) { 

      if (id == DLG_ID_TESTER) { 
       String val = inputTester.getText().toString(); 
       testerName = val; 
       txtTesterName.setText(testerName); 
      } else if (id == DLG_ID_DEVICE) { 
       String value = inputDevice.getText().toString(); 
       deviceId = value; 
       txtDeviceId.setText(deviceId); 

      } 
      return; 
     } 

    }); 

    builder.setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        return; 

       } 
      }); 

    return builder.create(); 
} 

回答

1

試試這個Link for Opening Dailog without touching Edittext

**YOUR_VIEW**.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       InputMethodManager keyboard = (InputMethodManager) 
       getSystemService(Context.INPUT_METHOD_SERVICE); 
       keyboard.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
      } 
     },200); 
+0

感謝您的鏈接 – user1767260

0

您可以覆蓋OnFocusChange()方法時看到整個對話框獲得焦點,然後調用getWindow( ).setSoftInputMode()具有「始終可見」的輸入模式。

相關問題