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>
나에게 솔루션을 제공하십시오 다음과 같습니다. 미리 감사드립니다.
당신은 "ROW_ID"또는 "ROW_NAME"또는 둘 모두를있는 텍스트 뷰를 표시되지 setListAdapter –
후) (myAdapter.notifyDataSetChanged 시도 했습니까? – TheLittleNaruto