0

I get some data from the database and try to fill them in a listview. i have checked through cursor.count() there is data exist but the listview show anything :/

I use a simpleCursorAdapter:

    rubDb.open();   
    cur = rubDb.getRubParent();     
    startManagingCursor(cur);
    Log.d("cursor length",Integer.toString(cur.getCount()));
    String[] from = new String[] { RubriqueDbAdapter.RUB_NOM, RubriqueDbAdapter.RUB_VISUEL };       
    int[] to = new int[] {R.id.title, R.id.icon};
    listAdapter = new SimpleCursorAdapter(this,  R.layout.itemgauche, cur, from, to);
    listeGauche.setAdapter(listAdapter);


public Cursor getRubParent() {              
    Cursor cursorResults = mDb.rawQuery("SELECT * FROM " + TABLE_RUBRIQUE + " WHERE rub_id_parent = 0 ORDER BY rub_ordre ASC", null);       
    return cursorResults;
}

how can I get a picture from the sdcard and put it on the ImageView in the listview ?

Thanks for your help !

3
  • post the getView() method from your adapter class. Commented Mar 13, 2012 at 16:09
  • I did not override getView() :s Commented Mar 13, 2012 at 16:17
  • ok, I make a customlistadapter which extends ArrayAdapter, here the getView() method, but now how to setText with the right title extract from the database? tx Commented Mar 13, 2012 at 16:37

1 Answer 1

1

First, you should be using a CursorAdapter, perhaps a SimpleCursorAdapter, instead of manually copying all of the data into objects in an array, just to use ArrayAdapter.

Second, if your list will be anything other than a simple piece of text, you must teach the adapter how to do whatever else you want. With SimpleCursorAdapter, you could associate a ViewBinder with it, or subclass SimpleCursorAdapter and override setViewImage(), or subclass SimpleCursorAdapter and override bindView().

Sign up to request clarification or add additional context in comments.

2 Comments

Ok I made some changes, can you check it please
@Remy: To use CursorAdapter or subclasses, you need an _id column in the Cursor. Typically, that would be the primary key of the table you are querying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.