액션

2012-11-19 5 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

setLines(1) 대신 setSingleLine(true)을 사용해야하고 키가 필요합니다. 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에서'android : singleLine = "true"'가 사용되지 않지만, 'android : maxLines = "1"'이라는 속성을 제안하는 것은 android : imeOptions = "actionDone"'에서는 작동하지 않는다는 점에 흥미 롭습니다. 내가 쓸모없는 것을 사용할 것 같아. – tymbark