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>
Logcat에서 예외가 발생했습니다. 여기를 확인하고 붙여 넣으십시오. –
나는 거기에 예외를 얻지 않을거야. 나는 문제가 setListAdapter (메모)에 있다고 생각 -> 이것은 단지 간단한 adapter.But 커서 어댑터를 사용하고 있습니다. – Prakash
무엇을 확인하십시오. c.getCount(); 로그를 사용하여 반환됩니다. 커서가 레코드를 보유하지 않습니다. –