Android 安卓-对话框按钮点击->;编辑文本值
我的选项菜单中有一个“搜索”按钮,显示一个带有搜索掩码的对话框。 因此,当你点击搜索按钮时,它应该开始实际的搜索 我在onCreateDialog中尝试做的是:Android 安卓-对话框按钮点击->;编辑文本值,android,dialog,onclick,android-edittext,Android,Dialog,Onclick,Android Edittext,我的选项菜单中有一个“搜索”按钮,显示一个带有搜索掩码的对话框。 因此,当你点击搜索按钮时,它应该开始实际的搜索 我在onCreateDialog中尝试做的是: Button search_button = (Button) dialog.findViewById(R.id.d_search_button); search_button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
Button search_button = (Button) dialog.findViewById(R.id.d_search_button);
search_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText text = (EditText) v.findViewById(R.id.d_search_text);
}
});
因为文本是空的,所以它不起作用,那么访问搜索文本的最佳方式是什么?将
EditText
作为最终的全局变量。并在设置事件时进行设置,则无论事件何时触发,该事件都将可用:
Button search_button = (Button) dialog.findViewById(R.id.d_search_button);
text = (EditText) v.findViewById(R.id.d_search_text);
search_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//get your text here
}
});
使
EditText
成为最终的全局变量。并在设置事件时进行设置,则无论事件何时触发,该事件都将可用:
Button search_button = (Button) dialog.findViewById(R.id.d_search_button);
text = (EditText) v.findViewById(R.id.d_search_text);
search_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//get your text here
}
});
我现在觉得有点傻,我真的能想到这一点。萝莉现在觉得自己有点傻,我真的能想到这一点。英雄联盟