Why There Is Only One Data In The List?
I used cursor for database selecting and want to put all the data inside a List, then return to the mainactivity. But after debugging, I found that there is only the first data ins
Solution 1:
public List<String> select1 (String ReservedState, String mycity, String mystreet, String mypostcode){
ReservedState="Free";
SQLiteDatabase Database1=dbHelper1.getWritableDatabase();
String[] columns={DbHelper1.KEY_ID1,DbHelper1.KEY_RESERVEDSTATE, DbHelper1.KEY_GEOGRAPHICALLOCATION,DbHelper1.KEY_CITY,DbHelper1.KEY_POSTCODE,DbHelper1.KEY_STREET};
Cursor cursor=Database1.query(DbHelper1.TABLE_NAME_1,columns, DbHelper1.KEY_RESERVEDSTATE+"='"+ReservedState+"' AND "+DbHelper1.KEY_CITY+"='"+mycity+"' AND "+DbHelper1.KEY_POSTCODE+"='"+mypostcode+"' AND "+DbHelper1.KEY_STREET+"='"+mystreet+"'",null,null,null,null);
Log.e("Cursor",""+cursor.getCount());
//StringBuffer buffer=new StringBuffer();
List<String> list=new ArrayList<String>();
do{
int index1=cursor.getColumnIndex(DbHelper1.KEY_ID1);
String id=cursor.getString(index1);
list.add(id);
}while(cursor.moveToNext());
return al;
}
Try this. Hope this will help.
Post a Comment for "Why There Is Only One Data In The List?"