lundi 14 mars 2016

Retrieve cursor from sqldatabase and present it using simple cursor adapter

I am trying to create a database and add the items of list view to the database. I have succeeded in creating the database and adding the data to database.My problem is in presenting the data as cursor using simple cursor adapter. When I tried to use toast,it works.My problem is with cursor I think.... Here's my method in DBAdapter

  public Cursor getAllRecords(){
    String where=null;
Cursor c=db.query(true,DATABASE_TABLE,new String[]{KEY_TITLE,KEY_ALBUM},where,null,null,null,null,null);
if(c!=null){
    c.moveToFirst();
}
    return c; }

This is my method to populate the list...

 private void populatelist(){
    db.open();
     c=db.getAllRecords();
     if(c!=null){
    String[] fields=new String[]{DBAdapter.KEY_TITLE,DBAdapter.KEY_ALBUM};
    int[] intof=new int[]{R.id.data_item_layoutTextView,R.id.dataitemlayoutTextView1};
    SimpleCursorAdapter mAdap=new SimpleCursorAdapter(getBaseContext(),R.layout.data_layout,c,fields,intof,0);
    ListView lv=(ListView)findViewById(R.id.data_layoutListView);
    lv.setAdapter(mAdap);
    }else{
        Toast.makeText(getApplicationContext(),"Nothing!!!",1000).show();
    }
    db.close();
}

Please Help me

Aucun commentaire:

Enregistrer un commentaire