我的应用程序在对话框中有一系列TextView,其中键盘受阻。我正在尝试使用以下代码来使用事件来使键盘消失。它不会编译,因为它说'void是变量构建器的无效类型'!
@Override
protected Dialog onCreateDialog(int id) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = layoutInflater.inflate(R.layout.exindex_dialog, (ViewGroup) findViewById(R.id.ex_index));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setOnItemSelectedListener((OnItemSelectedListener) arg0);
{
public void builder.filterStr2.isSelected(); //error is here
{
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(filterStr2.getWindowToken(), 0);
}
}
}
我做错了什么?
答案 0 :(得分:0)
编译器不明白你想要做什么,但我也不知道......
什么是arg0
?
也许您正在尝试为OnItemSelectedListener
定义builder
侦听器,但如果是这种情况,则必须实现onItemSelected()和onNothingSelected()方法......
因此,我不理解“isSelected”行...
也许,你想要做的更像是:
builder.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if (arg3 == filterStr2.id) { // You should maybe change this
// conditional
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(filterStr2.getWindowToken(), 0);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing
}
});