2
我正在使用ListActivity以SimpleCursorAdapter顯示簡單文本以從我的數據庫中獲取文本。我試圖調試問題並發現遊標正在成功獲取結果,但文本不會顯示在ListView中。無法在ListView中看到文本
以下是我正在使用的ListActivity代碼。
public class MyListActivity extends ListActivity{
Cursor myCursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
myCursor = getData();
startManagingCursor(myCursor);
ListAdapter myAdapter = new SimpleCursorAdapter(this, R.layout.display_details, myCursor, new String[]{MyDbHelper.ID_FIELD, MyDbHelper.NAME_FIELD}, new int[]{R.id.row_id, R.id.row_name});
setListAdapter(myAdapter);
}
private Cursor getData() {
return MyDBHelper.getRoutes();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
routesCursor.close();
}
}
和以下是ListView中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/row_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/row_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/row_id"
android:layout_toRightOf="@+id/row_id"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
每一行我的xml文件和我的ListActivity佈局如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent">
</ListView>
</RelativeLayout>
請給我提供瞭解決方案。提前致謝。
你嘗試setListAdapter –
後myAdapter.notifyDataSetChanged(),它的TextView沒有顯示 「ROW_ID」 或 「ROW_NAME」 或兩者兼而有之? – TheLittleNaruto