Итак, я уже несколько дней пытаюсь заставить ListView отображать данные из базы данных SQLite, но до сих пор не могу найти решение.
XML ListView выглядит так:
<?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="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/gotoEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Entry" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list" >
</ListView>
</LinearLayout>
с элементом строки, выглядящим следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15dp"
android:padding="15dp"
android:id="@+id/thetext"
>
</TextView>
Мой курсорный адаптер выглядит так:
public class ItemAdapter extends CursorAdapter{
private Cursor iCursor;
private Context iContext;
private final LayoutInflater iInflater;
public ItemAdapter(Context context, Cursor c) {
super(context, c);
iInflater=LayoutInflater.from(context);
iContext=context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView itemName = (TextView) view.findViewById(R.id.thetext);
itemName.setText(cursor.getString(cursor.getColumnIndex(db_Setup.KEY_NAME)));
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) throws InflateException {
final View view = iInflater.inflate(R.layout.single_item, parent, false);
return view;
}
}
Курсор делается с помощью этого метода:
public static Cursor getName() {
Cursor q = myDatabase.query(DATABASE_TABLE, new
String[] {db_Setup.KEY_NAME}, null, null, null, null, null);
q.moveToFirst();
return q;
}
и создан в listactivity следующим образом:
Cursor cursor = db_Setup.getName();
Я пытаюсь сделать это в своей ListActivity, чтобы привязать список к курсору:
ItemAdapter ia = new ItemAdapter(getBaseContext(), cursor);
ia.bindView(findViewById(R.id.thetext), getApplicationContext(), cursor);
Когда я запускаю приложение, ошибок нет... все есть кнопка из XML в верхней части этого поста и пустое место (без listView)... Я ввел некоторые значения в базу данных SQLite уже с чем-то вроде 14 значения или около того. Почему ничего не показывает?