-1

私は AlertDialog を持っています。その中には、EditText と 2 つの典型的なボタン ([キャンセル] と [OK]) があります。

正常に動作しますが、Edittext の keyDone をインターセプトする必要があるため、AlertDielog を閉じる必要があります。

    public static void  Dialogo_Observaciones(Context context) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("Observaciones");
    builder.setMessage("Ingrese las observaciones");

    final EditText input = new EditText(context);
    input.setInputType(InputType.TYPE_CLASS_TEXT );
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);

    input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId ==6){
            //HERE I must close the AlertDialog and others things   
            }
            return false;
        }
    });


    builder.setView(input);

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String Valor = input.getText().toString();
            if (Valor.equals("") ==false ){

                Variables.Observaciones = Variables.Observaciones + " " + Valor.trim();
                Variables.Observaciones = Variables.Observaciones.trim();
                dialog.cancel(); 


            }else{
                dialog.cancel();  

            }
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();   

        }
    });

    builder.show();

}

前もって感謝します。

4

1 に答える 1

0

使ってみて

dialog.dimiss()

キャンセルの代わりに。

また、if ステートメントの本体のコードが、期待どおりに実行されることを確信していますか?

于 2012-08-03T18:16:36.000 に答える