【问题标题】:How to access DialogFragment from onEditorActionListener?如何从 onEditorActionListener 访问 DialogFragment?
【发布时间】:2016-07-13 20:08:13
【问题描述】:

我正在为我的应用程序构建一个搜索对话框,用户在其中将搜索查询放入 EditText 并按 Enter,这应该会触发搜索。以下来自我的 onCreateDialog 方法:

   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);

当用户按下搜索按钮时如何取消对话框?

【问题讨论】:

    标签: android android-fragments android-context dialogfragment


    【解决方案1】:

    DialogFragment 上调用dismiss() 以删除对话框。它可能看起来像:MyDialogFragment.this.dismiss()

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多