I’m doing a standard SQL query in Android:
String selection = "SELECT phraseA, phraseB FROM TableXYZ";
Cursor c1;
c1 = myDbHelper.myDataBase.rawQuery(selection,null);
c1.moveToNext();
while(!c1.isLast()){
toplist.add("Phrase: "+c1.getString(0)+" "+c1.getString(1);
c1.moveToNext();
}
c1.close();
The table is very small and the number of returned stirngs is less than 40. Toplist is an ArrayList. It is put into a ListView.To the best of my knowledge this should show me 40ish strings. Now, what happens is the strings are shown but then another load of empty ListView fields come up. I have no idea how. I thought my iteration might be wrong, but I can’t find fault with it.
Aren’t you skipping the last result always? I think you need:
while(!c1.isAfterLast())to keep from skipping the last item.Also this line has a syntax error:
you are missing a “)” character.
As for your question, you aren’t showing enough code to really see what the problem is. Are you sure you aren’t adding any empty values to the ArrayList at some other point in your code? All you are showing here is how you are populating an array list, not how you are populating a ListView. Show your ListView code.
It would also be fairly trivial to attach the debugger to see what your ArrayList contains after this step, to see if the error is in this part of your code or somewhere else. Or for that matter even printing the ArrayList size to LogCat would help in debugging this.