Я не знаю, в чем проблема, потому что вы дали нам код без ошибок, В eclipse -> Window -> Open Perspective -> DDMS. Посмотрите на бревенчатую кошку, когда вы приблизитесь. Любой как. Вот пример, мой друг.
Основной список XML ... вы можете добавить представление списка в любом месте макета ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#FFFFD0"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:cacheColorHint="#666666"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:textColor="#4B89E0"
android:layout_height="wrap_content"
android:text="The list is empty! Do I need this? No idea!"
/>
</LinearLayout>
Следующая строка:
Теперь это может быть довольно сложно. У меня есть программа со списком, имеющим 5 изображений и 3 вида текста, и Android, кажется, справляется с этим довольно хорошо. Но вот основной, 3 вида текста ... может работать и с одним.
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/text1"
android:textColor="#4B89E0"
android:layout_width="130dip"
android:layout_height="40dip"
android:textSize = "15dip"
/>
<TextView android:id="@+id/text2"
android:textColor="#4B89E0"
android:layout_width="70dip"
android:gravity = "center"
android:textStyle = "bold"
android:layout_height="wrap_content" />
<TextView android:id="@+id/text3"
android:textColor="#4B89E0"
android:gravity = "center"
android:layout_width="80dip"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
И, наконец, некоторый код, чтобы собрать его вместе ... В этом примере вызов fillData (); заполнить список. Мне обычно нравится делать это так, чтобы при изменении базы данных информацию, которую я получаю (т.е. я хочу видеть: все фигуры, круглые или квадратные фигуры), список легко обновлялся. Я предполагаю, что ваша база данных уже открыта. Вы открыли его в OnCreate ().
Вместо того, чтобы весь этот код в вашем методе OnCreate создать свой собственный метод "fillData", и все, что вам нужно иметь в вашем OnCreate, это fillData (); . Это упростит просмотр, редактирование и устранение неполадок.
private void fillData() {
Cursor fetchInfo = mDbHelper.fetchAllRecords();
startManagingCursor(fetchInfo);
// Create an array to specify the fields we want to display in the list (TITLE,DATE,NUMBER)
String[] from = new String[]{DbAdapter.KEY_TITLE,
DbAdapter.KEY_DATE, DbAdapter.KEY_AUTHOR };
// an array of the views that we want to bind those fields to (in this case text1,text2,text3)
int[] to = new int[]{R.id.text1, R.id.text2, R.id.text3};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.list_row, fetchInfo, from, to);
setListAdapter(notes);
}
WakaWaka
GoodLuck