2012-07-09 3 views
0

내 응용 프로그램에서 데이터베이스의 값을 listview에 표시하려고합니다. cursoradapter에 데이터를 추가 할 수 없습니다. 간단한 어댑터 예제에서 코드를 언급했지만 cursoradapter과 함께 문제가 발생했습니다 (아무 것도 해당 활동에 표시되지 않습니다).안드로이드에서 Cursoradapter listview

super.onCreate(savedInstanceState); 
setContentView(R.layout.report); 
db.open(); 
Cursor c = db.getAllTitles(); 
startManagingCursor(c); 
String[] from = new String[] { db.KEY_INCOME,db.KEY_DESC}; 
int[] to = new int[] {R.id.text1 ,R.id.text2}; 
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.columnview, c, from, to); 
//System.out.println("notes="+notes.getCount()); 
setListAdapter(notes);  

내 mainXml 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#bfffdf" 
    android:drawSelectorOnTop="false"> 
</ListView> 

내 열 XML : 여기

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:paddingTop="4dip" 
    android:paddingBottom="6dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView android:id="@+id/text1" 
     android:textColor="#00ff00" 
     android:textSize="18sp" 
     android:layout_width="30dip" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@+id/text2" 
     android:textColor="#ff0000" 
     android:textSize="18sp" 
     android:layout_width="110dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 

</LinearLayout> 
+0

Logcat에서 예외가 발생했습니다. 여기를 확인하고 붙여 넣으십시오. –

+0

나는 거기에 예외를 얻지 않을거야. 나는 문제가 setListAdapter (메모)에 있다고 생각 -> 이것은 단지 간단한 adapter.But 커서 어댑터를 사용하고 있습니다. – Prakash

+0

무엇을 확인하십시오. c.getCount(); 로그를 사용하여 반환됩니다. 커서가 레코드를 보유하지 않습니다. –

답변

0

가고

여기 내 코드입니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingBottom="6dip" 
    android:paddingTop="4dip" > 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" 
     android:layout_weight="1" 
     android:textColor="#00ff00" 
     android:textSize="18sp" /> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textColor="#ff0000" 
     android:textSize="18sp" /> 

</LinearLayout> 
관련 문제