ast*_*ter 9 arrays android cursor android-listview
我有一个适配器类,它是扩展GroupingCursorAdapter和类型的构造函数
Adapter_Contacts(Context context, Cursor cursor, AsyncContactImageLoader asyncContactImageLoader).
我想用同一个类来填充我的ListView.我从一个Web服务获取数据JSON.
所以我的问题是,我怎么能转换JSONArray到Cursor使用相同的适配器类?
所以我的问题是,如何将JSONArray转换为Cursor以使用相同的适配器类?
您可以将其转换JSONArray为MatrixCursor:
// I'm assuming that the JSONArray will contain only JSONObjects with the same propertties
MatrixCursor mc = new MatrixCursor(new String[] {"columnName1", "columnName2", /* etc*/}); // properties from the JSONObjects
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = jsonArray.getJSONObject(i);
// extract the properties from the JSONObject and use it with the addRow() method below
mc.addRow(new Object[] {property1, property2, /* etc*/});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4308 次 |
| 最近记录: |