遍历来自 Sqlite-query 的行 [英] Iterate through rows from Sqlite-query
问题描述
我有一个表格布局,我想用数据库查询的结果填充它.我使用全选,查询返回四行数据.
I have a table layout that I want to populate with the result from a database query. I use a select all and the query returns four rows of data.
我使用此代码填充表格行内的 TextViews.
I use this code to populate the TextViews inside the table rows.
Cursor c = null;
c = dh.getAlternative2();
startManagingCursor(c);
// the desired columns to be bound
String[] columns = new String[] {DataHelper.KEY_ALT};
// the XML defined views which the data will be bound to
int[] to = new int[] { R.id.name_entry};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.list_example_entry, c, columns, to);
this.setListAdapter(mAdapter);
我希望能够将 KEY_ALT 的四个不同值分开,并选择它们的去向.我希望它们填充四种不同的 TextView,而不是上面示例中的一种.
I want to be able to separate the four different values of KEY_ALT, and choose where they go. I want them to populate four different TextViews instead of one in my example above.
如何遍历结果游标?
推荐答案
您可以使用下面的代码遍历游标并将它们存储在字符串数组中,然后您可以在四个 textview 中设置它们
You can use below code to go through cursor and store them in string array and after you can set them in four textview
String array[] = new String[cursor.getCount()];
i = 0;
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
array[i] = cursor.getString(0);
i++;
cursor.moveToNext();
}
这篇关于遍历来自 Sqlite-query 的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!