Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: setListAdapter sets only last row in database
    primarykey
    data
    text
    <p>as the title states I am having a little trouble linking my data from a database to a listview, the problem being that the adapter will set only the last row returned, as opposed to each row from the database table.</p> <p>An example of what I am trying to achieve:</p> <p>TABLE ANIMAL: Monkey Cat Dog Tiger</p> <p>will show up as only Tiger on screen.</p> <p>My method returning cursor from the database:</p> <pre><code>public Cursor retrieveAnimals(){ return = DB.query(ANIMAL_TABLE, new String[] { KEY_ROWID, KEY_ANIMALNAME, }, null, null, null, null, null); } </code></pre> <p>and setting the listview</p> <pre><code> dbm = new MyDBManager(this); dbm.open(); dbm.deleteAnimals(); dbm.populateDB(); // after populating, set the adapter.. myCursor = dbm.getAllAnimals(); String[] columns = new String[] {"animal_name"}; int[] to = new int[] {R.id.animal}; SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.row, myCursor, columns, to); this.setListAdapter(mAdapter); </code></pre> <p>I have a feeling my problem lies in the cursor position, in that it is moving automatically to the last row when setting the adapter, I have been trying to find a solution to my problem but with no luck.</p> <p>Thanks in advance for any suggestions.</p> <p>EDIT: Method to populate DB</p> <pre><code>public long populateDB(){ ContentValues initialValues = new ContentValues(); for(int i = 0; i &lt; animalName.length; i++){ initialValues.put(KEY_ANIMALNAME, animalName[i]); } return DB.insert(ANIMAL_TABLE, null, initialValues); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload