0

我的应用程序在键盘妨碍的对话框中有一系列 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);
         }      
    }
}

我究竟做错了什么?

4

1 回答 1

0

好吧,编译器不明白你要做什么,但我也不...

是什么arg0

也许您正在尝试OnItemSelectedListener为您builder的 .

因此,我不明白“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
        }

    });
于 2012-11-28T18:32:33.933 回答