コマンドを使用してListView
にAndroidを移植する際に問題が発生しました。AndroidでrawQueryコマンドを使用してリストビューを作成できません
私は正しく動作していると思われるassetsフォルダから自分のデータベースをコピーする方法を使用しています。私はこれがDDMS
で起こるのを見ているので、データベースは正しくコピーされています。私はまた、データベースが正しく開かれていると私に言っているlog.i
のエントリを取得しています。 Logcatを使用してもエラーは発生しませんが、何も私のListView
に入力されていません。
DBに問い合わせて報告するには、以下のコマンドに何か問題がありますか?
ご協力いただければ幸いです。ここで
private void fillData() {
Cursor c = myDbHelper.rawQuery("SELECT name FROM sqlite_master", null);
startManagingCursor(c);
// Create an array to specify the fields we want to display in the list.
String[] from = new String[]{"name"};
// an array of the views that we want to bind those fields too.
int[] to = new int[]{R.id.listview};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.list_view, c, from, to);
setListAdapter(notes);
}
は、私は、リストビューの結果を移入したい私のlists.xmlファイルです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:text = "Lists"
style="@style/HeaderText"
android:textSize="15dp"
android:gravity="center" />
<View
android:layout_width="wrap_content"
android:background="@drawable/gradient"
android:layout_height="1dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/searchButton"
android:text="Search"
android:background = "@drawable/main_buttons"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />"
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:text="No data"
style="@style/ButtonText"/>
</LinearLayout>
</LinearLayout>
そして最後に、list_view
レイアウトがrawQuery
から正しいリストを移入するだけTextView
ですコマンド。
'listview'と呼ばれる' list_view'の 'TextView'はあなたですか? –
はい、そうです。私はちょうどここにそれをコピーしていない。 – ADK
@ADKこのメソッドを 'fillData()'と呼んでもよろしいですか? 'SimpleCursorAdapter'は' _id'( 'INTEGER PRIMARY KEY AUTOINCREMENT')フィールドの一部として('あなたがあなたのクエリに持っていない) 'これを基にしたカーソルが' Exception'を投げるべきであることを要求します。また、 'rawQuery'で何をしたいのですか?' SQLite'データベースのテーブルの名前を取得しますか? – Luksprog