Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[2] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...