您好我想请求协助如何填充我的ListView我从远程数据库检索数据并将其添加到矩阵光标但是它只添加检索到的最终记录因此我的列表只有一条记录我不不知道它是我的循环还是我如何向光标添加数据请帮助
这是我当前的代码
try{ JSONArray jArray = new JSONArray(result); for(i=0;i<jArray.length();i++){ json_data = jArray.getJSONObject(i); _id = json_data.getInt("_id"); rec_words = json_data.getString("words"); rec_word = json_data.getString("word"); rec_word2 = json_data.getString("word2"); rec_description = json_data.getString("definition"); // cursor.addRow(items); // System.out.println(mld.query); // items.add(_id); // items.add(rec_word); //items.add(rec_word2); //items.add(rec_words); //items.add(rec_description); //System.out.println(items); final String[] matrix = { "_id","words","word", "word2","definition"}; cursor = new MatrixCursor(matrix); //cursor.addRow(new Object[] {json_data.getInt("_id"),json_data.getString("words"),json_data.getString("word"),json_data.getString("word2"),json_data.getString("definition")}); cursor.addRow(new Object[] {_id,rec_words,rec_word,rec_word2,rec_description}); // cursor.addRow(items); Log.i("log_tag","_id: "+json_data.getInt("_id")+ ", word: "+json_data.getString("word")+ ", word2: "+json_data.getString("word2")+ ", definition: "+json_data.getString("definition") ); //Get an output to the screen returnString += "\n\t" + jArray.getJSONObject(i); //System.out.println(returnString); } }catch(JSONException e){ Log.e("log_tag", "Error parsing data "+e.toString()); }
答案 0 :(得分:0)
使用此代码循环光标:
if (myCursor.moveToFirst()) {
do {
//get cursor data
} while (myCursor.moveToNext());
}
击> 修改强>
删除第cursor = new MatrixCursor(matrix);
行