Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

android - Invisible ListView items

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...