2013-05-01 3 views
0

배열의 항목으로 ListView를 채우려 고합니다. aparently 모든 것이 잘 작동하지만 앱을 실행하면 ListView가 비어 있습니다.하지만 사실이 아닙니다. 문제는 그것이 실제로 비어 있지 않고, 아이템이 보이지 않는다는 것입니다. 그리고 클릭했을 때만 나타납니다.보이지 않는 ListView 항목

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); 

그리고 ListView를 참조하는 활동의 XML 파일의 "코드"블록 :

여기 내 코드의

<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> 

어떤 생각?

감사합니다. :)

+0

응용 프로그램 컨텍스트 대신 제안 활동 컨텍스트 사용 http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context – Raghunandan

+0

OMG ... 작동합니다! 정말 고맙습니다!! 나는 안드로이드와 꽤 안돼서 ... 작동합니다! 굉장해 !! 정말 고맙습니다 :) – wrrzag

답변

1

문제가 될 수있는 응용 프로그램 컨텍스트를 사용 중입니다. 응용 프로그램 컨텍스트 대신 활동 컨텍스트를 사용해야합니다.

listView Items의 배경이 텍스트 색과 동일 할 수도 있습니다. listView 배경을 변경하십시오.

관련 문제