I'm trying to populate a ListView with items from an Array, aparently everything works fine but when I run the app the ListView is empty... but it's not true. The problem is that it's actually not empty, the items are invisible... and only shown when I click on them.
Here's my code:
SQLite data = new SQLite(getApplicationContext());
db = data.getReadableDatabase();
String query = "SELECT question, corrOp, inc1, inc2, inc3 FROM questions WHERE idCat = '" + bundle.getInt("CAT") + "' ORDER BY RANDOM() LIMIT 5";
c = db.rawQuery(query,null);
startManagingCursor(c);
c.moveToFirst();
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
Pregunta aux = new Pregunta();
aux.initValues(c.getString(0), c.getString(1), c.getString(2), c.getString(3), c.getString(4));
p.add(aux);
}
lbl.setText(p.get(0).getQuestion());
ArrayList<String> r = new ArrayList<String>();
r.add(p.get(0).getCorrect());
r.add(p.get(0).getIncorrect1());
r.add(p.get(0).getIncorrect2());
r.add(p.get(0).getIncorrect3());
Collections.shuffle(r);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, r);
lst.setAdapter(adapter);
And the "code" block of the xml file of the Activity which refers to the ListView:
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp" >
</ListView>
Any idea??
Thanks!! :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…