0

运行后,query我有如下数据cursor

ID| TOPIC | TITLE | TYPE | NAME |
---------------------------------
1 | AB    | BCD   | ref  | Ferari|
----------------------------------
1 | AB    | BCD   | ref  | TOYOTA|
----------------------------------
2 | BC    | ABC   | notref| AUDI |
----------------------------------
2 | BC    | ABC    |notref| BMW  |

我怎样才能得到名字

4

2 回答 2

0

你可以得到名字............你可以将所有数据存储到一个arraylist......并根据id值检索数据......

尝试这个

ArrayList datas=new ArrayList();
ArrayList list=new ArrayList();
 String StoreTitle = "", StoreName="";
       cursor.moveToFirst();
       do{

           int getID = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
           String Title = cursor.getString(cursor.getColumnIndexOrThrow("TITLE"));
           String StoreName= cursor.getString(cursor.getColumnIndexOrThrow("NAME"));

           if(StoreTitle.equalsIgnoreCase(Title)){
               list=new ArrayList();
               String getTopic = cursor.getString(cursor.getColumnIndexOrThrow("TOPIC"));
               String getTitle = cursor.getString(cursor.getColumnIndexOrThrow("TITLE"));
               String getType = cursor.getString(cursor.getColumnIndexOrThrow("TYPE"));
               String getName = cursor.getString(cursor.getColumnIndexOrThrow("NAME"));
               String name=StoreName+" "+getName;
               list.add(getTopic);
               list.add(getTitle );
               list.add(getType );
               list.add(name);
               datas.remove(getID);
               datas.add(getID ,list);
           }
           else
           {
               list=new ArrayList();
               String getTopic = cursor.getString(cursor.getColumnIndexOrThrow("TOPIC"));
               String getTitle = cursor.getString(cursor.getColumnIndexOrThrow("TITLE"));
               String getType = cursor.getString(cursor.getColumnIndexOrThrow("TYPE"));
               String getName = cursor.getString(cursor.getColumnIndexOrThrow("NAME"));
               String name=StoreName+" "+getName;
               list.add(getTopic);
               list.add(getTitle );
               list.add(getType );
               list.add(name);
               datas.add(getID ,list);
           }
           StoreTitle = Title;

     }while(cursor.moveToNext());
于 2013-07-31T05:17:16.337 回答
0

只需修改其他部分,跟踪位置变量

else
{
String name=arraylist[position].getName;
name=name+" "+cursor.getString(cursor.getColumnIndexOrThrow("Name"));
arraylist.setname(name);
}
于 2013-07-31T05:39:07.070 回答