我想查询表中的所有列成一个长文本视图和/或字符串。我知道这可能不是正确的方式去做事情,但我不得不这样做。纠正我,如果我错了,我是在IM pression的下一个移动将获得该行的下一列:
I am trying to query all the columns in a table into one long text view and/or string. I know this might not be the right way to do things but I have to do this. Correct me if I am wrong, I was under the impression that move next would get the next column in the row:
Cursor c = db.get();
if(c.moveToFirst){
do{
string = c.getString(0);
}while(c.moveToNext);
我想这会得到第一列显示的所有内容,而不是我得到的第一列和第一行。我究竟做错了什么?有没有更好的或者真正的方式来获得这些信息,而无需使用一个ListView?
I thought that this would get the first column and display all of its contents instead I get the first column and first row. What am I doing wrong? Is there a better or real way to get this information without using a ListView?
有关清晰完整的例子是如下这些我相信感兴趣。由于code评论指出,我们基本上是遍历数据库行,然后列,形成数据表作为每个数据库。
For clarity a complete example would be as follows which I trust is of interest. As code comments indicated we essentially iterate over database rows and then columns to form a table of data as per database.
Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null,
null);
//if the cursor isnt null we will essentially iterate over rows and then columns
//to form a table of data as per database.
if (cursor != null) {
//more to the first row
cursor.moveToFirst();
//iterate over rows
for (int i = 0; i < cursor.getCount(); i++) {
//iterate over the columns
for(int j = 0; j < cursor.getColumnNames().length; j++){
//append the column value to the string builder and delimit by a pipe symbol
stringBuilder.append(cursor.getString(j) + "|");
}
//add a new line carriage return
stringBuilder.append("\n");
//move to the next row
cursor.moveToNext();
}
//close the cursor
cursor.close();
}
上一篇:正在进行多播,可能有Wi-Fi Direct的?能有、正在进行、Wi、Fi
下一篇:Android的org.xmlpull.v1.XmlPullParserException解析XMLxmlpull、org、Android、XML