0

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?

trpnd
  • 455
  • 2
  • 10

1 Answers1

0

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

kris larson
  • 30,387
  • 5
  • 62
  • 74