在警告对话框框中带有复选框的列表视图

4

我正在显示联系人的多选“确定,取消”对话框。我已经为在对话框中显示联系人的适配器实现了可过滤性。问题是,当我使用类型前进时尝试选择(勾选)一个联系人时,该特定位置的复选框被选中而不是联系人。

初始屏幕如下所示:

进行类型前进后,

当我按退格键以查看原始列表时,所选联系人未被选中。

这是我的活动。

Cursor c = getContentResolver().query(People.CONTENT_URI,
    PROJECTION,
    null,
    null,
    Contacts.People.DEFAULT_SORT_ORDER
);

startManagingCursor(c);
ListAdapter adapter1 = new ContactListAdapter(this, c);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = (View) inflater.inflate(R.layout.list_view, null);
listView = (ListView) view.findViewById(R.id.contactlist);
listView.setTextFilterEnabled(true);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter1);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemSelectedListener(this);
alertDialog.setView(view);

适配器的作用如下:
public class ContactListAdapter extends CursorAdapter implements Filterable
{
    public static final String[] PEOPLE_PROJECTION = new String[] {
        People._ID,
        People.NAME,
        People.NUMBER
    };

    public ContactListAdapter(Context context, Cursor c) {
        super(context, c);
        mContent = context.getContentResolver();
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final TextView view = (TextView) inflater.inflate(
            android.R.layout.simple_list_item_multiple_choice,
            parent,
            false
        );
        view.setText(cursor.getString(1));
        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ((TextView) view).setTag(cursor.getLong(0));
        ((TextView) view).setText(cursor.getString(1));
    }

    @Override
    public String convertToString(Cursor cursor) {
        return cursor.getString(1);
    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (getFilterQueryProvider() != null) {
            return getFilterQueryProvider().runQuery(constraint);
        }

        StringBuilder buffer = null;
        String[] args = null;
        if (constraint != null) {
            buffer = new StringBuilder();
            buffer.append("UPPER(");
            buffer.append(Contacts.ContactMethods.NAME);
            buffer.append(") GLOB ?");
            args = new String[] { constraint.toString().toUpperCase() + "*" };
        }

        return mContent.query(Contacts.People.CONTENT_URI,
            PEOPLE_PROJECTION,
            buffer == null ? null : buffer.toString(),
            args,
            Contacts.People.DEFAULT_SORT_ORDER
        );
    }

    private ContentResolver mContent;

}

我认为你需要在你的适配器中添加控制复选框按钮行为的方法...我看不到,可能是原因... - JNI_OnLoad
1个回答

0

当我按退格键以查看原始列表时,所选联系人未被选中。

尝试为您的dialog.setOnCancleListener设置

并在onCancel调用adapter.notifyDataSetChanged()

也许会有帮助


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接