遍历从sqlite的查询行 [英] Iterate through rows from Sqlite-query

查看:276
本文介绍了遍历从sqlite的查询行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想填充从数据库中查询结果的表格布局。 我使用的是全选和查询返回四行数据。

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.

我用这个code来填充里面的表行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四个不同的值,并选择他们到何处去。我希望他们能够填充四种不同textviews而不是一个在我上面的例子。我怎样才能通过游标的最终迭代?

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. How can I iterate through the resulting cursor?

问候,AK

推荐答案

您可以使用下面code要经过光标并将它们存储在字符串数组后,您可以在四个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的查询行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆