0

こんにちは、私は SQLite データベースを持っており、単純なカーソルを使用してデータベースを読み取り、それを TextView に表示しています。ただし、データを ListView に表示したいと思います。

だから私は文字列を持っていますが、ListViewで表示する方法がわかりません。簡単な方法はありますか、それともある種のアダプターを作成する必要がありますか?

また、リスト ビューの一部をヘッダーに設定し、他の部分を小見出しに設定する方法についても考えていました。可能であれば、各行が異なるリスト項目になるようにしたいです。

4

2 に答える 2

0

SimpleCursorAdapterを使用します。

以下は簡単な例です。

    yourListView.setAdapter(new SimpleCursorAdapter(
    /* The context where the ListView associated with this SimpleListItemFactory is running */, 
    /* resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in "to" */, 
    /* The database cursor. Can be null if the cursor is not available yet. */,
    /* A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet. */, 
    /* The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet. */, 
    /* Flags used to determine the behavior of the adapter, as per CursorAdapter(Context, Cursor, int). */));
于 2012-07-16T21:00:29.603 に答える