SQLite 데이터베이스에 저장된 일부 데이터를 가져 와서 사용자 지정 목록보기에 표시하려고합니다.SimpleCursorAdapter를 사용하는 사용자 지정 ListView
파일 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
- VARCHAR
<?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 내가 SQLite 데이터베이스에서 데이터를 가져 와서 사용자 정의
ListView
에 표시 가야합니까 어떻게
? 데이터베이스가 이미 작성되어 채워지고 가정
감사합니다. @rciovati ... 코드에서 약간 작업해야하고 작동하도록했습니다! – arnabghosal