SQLite データベースに保存されているデータを取得して、カスタム リスト ビューに表示しようとしています。
ファイルSettle.java
:
public class Settle extends ListActivity {
SQLiteDatabase DB;
Cursor cur;
SimpleCursorAdapter mAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settle);
DB = openOrCreateDatabase("MoneyManager.db",MODE_PRIVATE,null);
cur = DB.rawQuery("SELECT * FROM Money",null);
String[] columns = new String[] {cur.getString(cur.getColumnIndex("name")),Double.toString(cur.getDouble(cur.getColumnIndex("amount")))};
int[] to = new int[] { R.id.settle_name,R.id.settle_amount};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.settle_entry, cur, columns, to);
this.setListAdapter(mAdapter);
}
protected void onDestroy() {
super.onDestroy();
DB.close();
}
}
ファイルSettle_entry.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/settle_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="@+id/settle_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
私のデータベーススキーマは
- 名前 - VARCHAR
- 金額 - REAL
- 理由 - VARCHAR
SQLite データベースからデータを取得して Custom に表示するにはどうすればよいListView
ですか?