0

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!! :)

wrrzag
  • 467
  • 6
  • 21
  • A suggestion use activity context in place of application context http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context – Raghunandan May 01 '13 at 06:59
  • OMG... it works!! Thank you so much!! I'm pretty newbie with android... it works!! Awesome!! Thank you so much :) – wrrzag May 01 '13 at 07:08

1 Answers1

1

You are using Application Context which may be a problem. You should use Activity Context instead of Application context.

It may be possible that the background of the listView Items is same as their text color. Change the listView background.