在 Android ICS 上,我的一个 ListView 中的多项选择被破坏

发布于 2024-12-29 10:30:54 字数 1469 浏览 3 评论 0原文

我的 Android 闪存卡应用程序有一个仅在 ICS 中发生的错误。复选框的行为类似于单选按钮,就像单选按钮一样。

public class CardSetListActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card_set_list);

        ListAdapter adapter = getSimpleCursorAdapter();
        // ListAdapter adapter = getArrayAdapter();

        ListView list = (ListView) findViewById(R.id.listView);
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setAdapter(adapter);
        list.setItemsCanFocus(false);
    }

    private ListAdapter getSimpleCursorAdapter() {
        CardsDbAdapter dbAdapter = CardsDbAdapter.getInstance(this);
        Cursor cursor = dbAdapter.fetchAllCardSets();
        startManagingCursor(cursor);
        String[] fromColumns = new String[] { CardsDbAdapter.COL_CARD_SET };
        int[] toResources = new int[] { android.R.id.text1 };
        return new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cursor, fromColumns, toResources);
    }

    private ListAdapter getArrayAdapter() {
        String[] GENRES = new String[] { "Action", "Adventure", "Animation" };
        return new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, GENRES);
    }
}

知道我可以在哪里寻找解决方案吗? 使用 SimpleCursorAdapter,复选框的行为类似于单选按钮。使用 ArrayAdapter,它们的行为是正确的。 我现在改用 ArrayAdapter,但仍然想知道这里发生了什么。

My android flash cards app has a bug that only occurs in ICS. The checkboxes behave like radiobuttons, like it was single-choice.

public class CardSetListActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card_set_list);

        ListAdapter adapter = getSimpleCursorAdapter();
        // ListAdapter adapter = getArrayAdapter();

        ListView list = (ListView) findViewById(R.id.listView);
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setAdapter(adapter);
        list.setItemsCanFocus(false);
    }

    private ListAdapter getSimpleCursorAdapter() {
        CardsDbAdapter dbAdapter = CardsDbAdapter.getInstance(this);
        Cursor cursor = dbAdapter.fetchAllCardSets();
        startManagingCursor(cursor);
        String[] fromColumns = new String[] { CardsDbAdapter.COL_CARD_SET };
        int[] toResources = new int[] { android.R.id.text1 };
        return new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cursor, fromColumns, toResources);
    }

    private ListAdapter getArrayAdapter() {
        String[] GENRES = new String[] { "Action", "Adventure", "Animation" };
        return new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, GENRES);
    }
}

Any idea where I could look for a solution?
With the SimpleCursorAdapter, the Checkboxes behave like RadioButtons. With the ArrayAdapter they behave right.
I'm changing to use ArrayAdapter now but would still like to know what's going on here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文