我有一个 AlertDialog,其中有一个 EditText 和两个典型的按钮([Cancel] 和 [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();
}
提前致谢。