I’m fetching Data form Table as list and adding that to sub list but i’m getting output that i didn’t expect. I don’t know how to Fix that so that i can get the output what i need.I have attached the code please help me to solve this issue??
public List<List<String>> fetchData(){
List<List<String>> main= new ArrayList<List<String>>();
List<String> sub= new ArrayList<String>();
String qry="SELECT * FROM "+myTable+"";
SQLiteDatabase db= this.getReadableDatabase();
Cursor cursor=db.rawQuery(qry, null);
if (cursor.moveToFirst()) {
do {
System.out.println("-TblPOmaster-");
sub.add(cursor.getString(0));
sub.add(cursor.getString(1));
sub.add(cursor.getString(2));
main.add(sub);
System.out.println("Data:"+main);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return main;
}
Output what i'm Getting Now
Data:[[a1,a2,a3]]
Data:[[a1,a2,a3,b1,b2,b3],[a1,a2,a3,b1,b2,b3]]
Data:[[a1,a2,a3,b1,b2,b3,c1,c2,c3],[a1,a2,a3,b1,b2,b3,c1,c2,c3],[a1,a2,a3,b1,b2,b3,c1,c2,c3]]
Output what i need
Data:[[a1,a2,a3]]
Data:[[a1,a2,a3],[b1,b2,b3]]
Data:[[a1,a2,a3],[b1,b2,b3],[c1,c2,c3]]
use this because you have to refrence new arraylist