Android - CheckBox在键盘上取消选中显示?

时间:2015-06-22 14:23:03

标签: android

对话框的内容是ListView,这里是适配器:

public class MultiSelectionSpinnerAdapter extends BaseAdapter {

    private Context ctx;
    private ArrayList<MultiSelectionItem> items;
    private LayoutInflater layoutInflater;

    public MultiSelectionSpinnerAdapter(Context ctx, ArrayList<MultiSelectionItem> items) {
        this.ctx = ctx;
        this.items = items;
        this.layoutInflater = LayoutInflater.from(ctx);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final MultiSelectionItem item = items.get(position);

        CheckBox checkBox;
        if (item.isEditable()) {
            convertView = layoutInflater.inflate(R.layout.editable_checkbox, parent, false);
            checkBox = (CheckBox) convertView.findViewById(R.id.editableCheckbox);

            EditText editText = (EditText) convertView.findViewById(R.id.editableEditText);
            editText.setText(item.getEditableValue());
            editText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {}

                @Override
                public void afterTextChanged(Editable s) {
                    item.setEditableValue(s.toString());
                }
            });
        } else {
            convertView = layoutInflater.inflate(R.layout.multi_selection_checkbox, parent, false);
            checkBox = (CheckBox) convertView;
        }
        checkBox.setText(item.getLabel());
        checkBox.setChecked(item.isSelected());
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                item.setIsSelected(isChecked);
            }
        });

        return convertView;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return items.get(position).getId();
    }
}

2 个答案:

答案 0 :(得分:0)

我通过添加

解决此问题
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

到mainfest文件。

答案 1 :(得分:-1)

您可以尝试here中提出的解决方案。 基本上设置SoftInputMode;像这样: dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);