我试图将表中的所有列查询为一个长文本视图和/或字符串.我知道这可能不是正确的做事方式,但我必须这样做.如果我错了,请纠正我,我的印象是,接下来的行将获得行中的下一列:
Cursor c = db.get();if(c.movetoFirst){do{string = c.getString(0);}while(c.movetoNext);
我认为这将获得第一列并显示其所有内容,而不是我得到第一列和第一行.我究竟做错了什么?有没有更好或真实的方法来获取这些信息而不使用ListVIEw?
解决方法:
为清楚起见,我认为有兴趣的完整例子如下.正如代码注释所示,我们基本上遍历数据库行,然后是列,以根据数据库形成数据表.
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(); }
总结 以上是内存溢出为你收集整理的android cursor.moveToNext()?全部内容,希望文章能够帮你解决android cursor.moveToNext()?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)