public class ABC extends ListActivity {
static final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abc_list);
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.abc_list_row,
new String[] {"AAA","BBB","CCC"},
new int[] {R.id.aa,R.id.bb, R.id.cc,}
);
add();
setListAdapter(adapter);
}
private void add() {
DatabaseA databaseHelper = new DatabaseA(this);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor c= db.rawQuery("select * from data", null);
HashMap<String,String> temp = new HashMap<String,String>();
while(c.moveToNext()){
Log.d("Debug", c.getString(2));
temp.put("AAA", c.getString(1));
temp.put("BBB", c.getString(2));
temp.put("CCC", c.getString(3));
list.add(temp);
}
c.close();
db.close();
for (Map.Entry<String, String> entry : temp.entrySet()) {
String xx= entry.getKey();
String yy = entry.getValue();
Log.d("data", xx+" : "+yy);
}
}
My Logcat:
D/Debug(657): New york
D/Debug(657): New moon
D/data(657): AAA : Aug 20, 2012 3:57:02 PM
D/data(657): BBB : New moon
D/data(657): CCC : Title
My problem is it always left out the first data from sqlite in this list. Besides, everytime i press a button to view this list, it will add those data into this list although they are already exist. I just want to view those data in sqlite in list form. Any way to solve this. Thanks.