Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用数据库中的数据填充ExpandableListView_Java_Android_Expandablelistview - Fatal编程技术网

Java 使用数据库中的数据填充ExpandableListView

Java 使用数据库中的数据填充ExpandableListView,java,android,expandablelistview,Java,Android,Expandablelistview,我有一个包含多个表的SQLite数据库。对于每个表,我都试图使用自定义CursorTreeAdapter来表示ExpandableListView中的所有数据。据我所知,getChildrenCursor方法返回一个游标,该游标指向填充子视图所需的数据。但是,对于如何使用groupCursor参数检索子游标,我没有具体的想法 @Override protected Cursor getChildrenCursor(Cursor groupCursor) { String[] projec

我有一个包含多个表的SQLite数据库。对于每个表,我都试图使用自定义CursorTreeAdapter来表示ExpandableListView中的所有数据。据我所知,getChildrenCursor方法返回一个游标,该游标指向填充子视图所需的数据。但是,对于如何使用groupCursor参数检索子游标,我没有具体的想法

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
    String[] projection = { "columnNeeded" };
    return context.getContentResolver()
            .query(CONTENT_URI, projection, null, null, null);
}
上面的方法将返回一个游标,该游标返回包含所需列的所有行。这样做对吗

在表的每一行的“ColumnRequired”列中,它包含jsonArray的字符串表示形式。我试图使用JSONArray将arrayList存储到表的每一行中。因此,我尝试检索此arrayList并使用此arrayList填充子视图,如下所示:

@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
    TextView name = (TextView) view.findViewById(R.id.summary_child_name);
    TextView bill = (TextView) view.findViewById(R.id.summary_child_bill);

    String arrayListString = cursor
            .getString(cursor.getColumnIndex("columnNeeded"));
    JSONObject json = new JSONObject();
    try {
        json = new JSONObject(arrayListString);
    } catch (JSONException e) {
        Log.e(LOG_TAG, "Unable to retrieve list of items");
    }
    JSONArray jsonArray = json.optJSONArray(ReceiptContract.JSONARRAY_NAME);
    // retrieveArrayList iterates through jsonArray and adds it to items 
    items = retrieveArrayList(jsonArray);

    name.setText(What do I put here?);
    bill.setText(What do I put here?);
}

如您所见,我已成功地将整个数组列表作为ArrayList类型对象检索。但是,我一直坚持在子视图中显示数组列表。你知道我该怎么做吗?

使用HashMap将数据存储为键值,并使用BaseExpandableListAdapter将数据填充到ExpandableListView将json字符串存储在sqlite表中??为什么?@pskink我在寻找将整个ArrayList存储在表的每一行中的方法,而不是创建另一个要引用的表。因此,我遇到了这样一个建议:你知道是否有更好的方法来实现同样的事情吗?json数组中有什么?只是一些线?它有多大?是否总是相同的大小?@pskink jsonArray包含字符串和双对。我用以下内容填充了jsonArray:jsonArray jsonArray=new jsonArray(itemsList),其中itemsList是一个ArrayList,用于保存具有自定义数据类型Item的对象。每个Item对象都包含一个字符串和一个双精度值。大小取决于早期活动中的用户输入。但是,我仍然希望用户能够修改数据库中的数据