问题描述:

I'm building a search dialog for my app in which the user puts their search query in an EditText and presses enter, which should trigger the search. The following is from my onCreateDialog method:

 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_search, null);

final EditText searchString = (EditText) dialogView.findViewById(R.id.searchInputET);

searchString.setOnEditorActionListener(new TextView.OnEditorActionListener() {

@Override

public boolean onEditorAction (TextView v, int actionId, KeyEvent event) {

if (actionId == EditorInfo.IME_ACTION_SEARCH) {

localSearch(v.getText().toString());

}

return false;

}

});

builder.setView(dialogView);

How do I cancel the dialog when the user presses the search button?

网友答案:

Call dismiss() on the DialogFragment to remove the dialog. It will probably look something like: MyDialogFragment.this.dismiss().

相关阅读:
Top