【问题标题】:ListActivity with checkbox in AndroidListActivity 与 Android 中的复选框
【发布时间】:2009-12-31 18:34:40
【问题描述】:

我正在尝试使用 ListActivity 和 SimpleCursorAdapter 根据来自数据库的查询来检查复选框。光标是问题和答案的列表。如果用户已经回答了一个问题,则应选中该复选框,但不会选中它们。代码如下所示:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.questions);


    Cursor c;
    testDbAdapter db = new testDbAdapter(this);
    c = db.getQuestions(Long.toString(mRowId), Integer.toString(mSection));
            startManagingCursor(c);

            String[] from = new String[]{testDbAdapter.QUESTIONS_Q, testDbAdapter.QUESTIONS_A};
            int[] to = new int[]{R.id.question, R.id.answer};

            SimpleCursorAdapter results = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, c, from, to);


            setListAdapter(results);
  }

【问题讨论】:

    标签: java android checkbox listadapter


    【解决方案1】:

    您可以扩展 Adapter 并覆盖 bindView 方法,或调用 setViewBinder。在此处的类似问题中回答了对此的几个详细解决方案:

    Android: Binding data from a database to a CheckBox in a ListView?

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多