2012-11-19 36 views
3

我有一個標準條目彈出的對話框行動在輸入對話框完成

AlertDialog.Builder builder = new AlertDialog.Builder(activity); 

    builder.setTitle(title) 
     .setMessage(message) 
     .setPositiveButton(buttonPositif, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        // Send the positive button event back to the host activity 
        mListener.onDialogPositiveClick(EntryDialogFacade.this); 
       } 
      }) 
     .setNegativeButton(buttonNegatif, new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        // Send the negative button event back to the host activity 
        mListener.onDialogNegativeClick(EntryDialogFacade.this); 
       } 
      });   

    editText = new EditText(activity); 
    editText.setLines(1); 
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE); 
    builder.setView(editText); 

    Dialog dialog = builder.create();   
    dialog.show(); 

我試圖顯示輸入字段鍵盤上的完成按鈕(見代碼段),但是,這不是以這種方式工作。

本來任何人都經歷了同樣的事情?

乾杯。

回答

4

您需要使用setSingleLine(true)而不是setLines(1),然後您需要EditorActionListener來捕獲Done密鑰。

editText.setSingleLine(true); 
editText.setImeOptions(EditorInfo.IME_ACTION_DONE); 
editText.setOnEditorActionListener(new OnEditorActionListener() { 

    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     Toast.makeText(MainActivity.this, "Got IME Done", Toast.LENGTH_SHORT).show(); 
     return true; 
    } 
}); 
+0

謝謝你,但它似乎沒有聽衆完美的工作。 –

+1

有趣的是'機器人:單線= 「真」'在XML已經過時,但提示屬性:'機器人:imeOptions = 「actionDone」':MAXLINES = 「1」'不'機器人工作。我想我會使用不贊成的... – tymbark