Jump to content

Peupler ListView (sans ListActivity) depuis SQLite


Recommended Posts

Bonjour tout le monde,

Je suis en train d'essayer de charger des données de SQLite dans une ListView (la ListView est dans un activité non ListActivity).

Ma bdd ressemble à ça :

private static final String APPLICATION_TABLE_CREATE =
               "CREATE TABLE application (" +
               "id INTEGER PRIMARY KEY, " +
               "fullname TEXT);";

Donc j'ai juste un fullname et un id, que je récupère comme ça

Cursor data = database.database.query("application", new String[] {"id as _id", "fullname"}, null, null, null, null, null);
   	startManagingCursor(data);
   	ListAdapter dataSource = new SimpleCursorAdapter(this, R.id.listviewapplication, data, new String[]{"fullname"}, new int[]{R.id.applicationlistviewitemtext}); 
   	lstApplication.setAdapter(dataSource);

Voila comme est "déclarée" ma ListView

<ListView 
               android:id="@+id/listviewapplication"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent">
               <TextView android:id="@+id/listviewapplicationtext"
               		  android:layout_width="fill_parent"
               		  android:layout_height="wrap_content" />

Mais j'obtiens l'erreur suivante dans le logcat :

05-13 13:58:13.599: ERROR/AndroidRuntime(27867): Caused by: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

Merci d'avance pour votre aide !!!

PoZZyX

Link to comment
Share on other sites

Bonjour,

Je ne comprend pas pourquoi tu mets un TextView dans ton ListView ? Attention, chaque item (chaque ligne) d'un tableau doit être définit dans une vue différente. Donc ton simple adapter ne doit pas prendre un id mais un layout.

Bon courage,

ichpa

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...