2012-07-18 32 views
0

我使用他们的id.I做泰德retreival中检索数据库从一个字符串,但它返回一些对象格式不作为string.Please帮助我..数据库retreival作为字符串的Android

我retreival地点:

db.open(); 
    for(int i=1;i<=5;i++) 
    {  
    if(i==1) 
     group1=db.getspintitle(1); 
    if(i==2) 
     group1=db.getspintitle(2); 
    if(i==3) 
     group1=db.getspintitle(3); 
    if(i==4) 
     group1=db.getspintitle(4); 
    if(i==5) 
     group1=db.getspintitle(5);  
    } 

db.getspintitle()方法:

public String getspintitle(int rowId)throws SQLException 
{ 

    String sumtotal=""; 
    Cursor cursor1 = db.rawQuery(
      "SELECT spin from spinner WHERE _id='rowId'", null); 
    sumtotal=cursor1.toString(); 
    cursor1.close();  
    return sumtotal; 
} 

回答

0

为了您的信息,下面的回报你的Cursor,而不是简单的字符串。

Cursor cursor1 = db.rawQuery("SELECT spin from spinner WHERE _id='rowId'", null); 

要从游标中检索值,必须遍历游标。现在

,在这里你的情况,你可以做如下:

Cursor cursor1 = db.rawQuery("SELECT spin from spinner WHERE _id='rowId'", null); 

    if (cursor != null && cursor.getCount() > 0) { 
     cursor.moveToNext(); 
     sumtotal= cursor.getString(0); 
     cursor.close(); 
    } 
+0

是帕雷什Mayani。我如何将它们转换为字符串..因为我必须将此值设置为textview在我的屏幕.. – 2012-07-18 07:05:26

+0

检查更新的答案。请牢记这一点,因为您还必须迭代游标来获取数据。 – 2012-07-18 07:07:37

+1

感谢它的工作/// – 2012-07-18 07:09:37

0
String[] sumTotal= new String[cursor.getCount()] 
    while(cursor.moveToNext()) 
     sumtotal[i] = cursor.getString(0);