SQLite查询:获取一行的所有列(android)?

这是架构:

在此处输入图像描述

SQL查询是:SELECT * from unjdat,其中col_1 =“myWord”;

即,我想显示col_1为myWord的行的所有列。

int i; String temp; words = new ArrayList(); Cursor wordsCursor = database.rawQuery("select * from unjdat where col_1 = \"apple\" ", null); //myWord is "apple" here if (wordsCursor != null) wordsCursor.moveToFirst(); if (!wordsCursor.isAfterLast()) { do { for (i = 0; i < 11; i++) { temp = wordsCursor.getString(i); words.add(temp); } } while (wordsCursor.moveToNext()); } words.close(); 

我认为问题在于循环。 如果我删除for循环并执行wordsCursor.getString(0)它可以工作。 如何循环获取所有列?

注意

  1. col_1永远不为null,对于某些行,col_2到col_11的任何一个都可以为null。
  2. 表中的所有列和所有行都是唯一的。

这应该是这样的

 Cursor cursor = db.rawQuery(selectQuery, null); ArrayList> maplist = new ArrayList>(); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { HashMap map = new HashMap(); for(int i=0; i 

编辑用户想知道如何使用HashMap填充ListView

 //listplaceholder is your layout //"StoreName" is your column name for DB //"item_title" is your elements from XML ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.listplaceholder, new String[] { "StoreName", "City" }, new int[] { R.id.item_title, R.id.item_subtitle });