【发布时间】: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