这是我的列表活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_list);
mDbHelper = new MyDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
private void fillData() {
// Get all of the rows from the database and create the item list
Cursor c = mDbHelper.fetchAllTransactions();
startManagingCursor(c);
// Create an array to specify the fields we want to display in the list
String[] from = new String[]{MyDbAdapter.KEY_DATE, MyDbAdapter.KEY_NAME};
// and an array of the fields we want to bind those fields to
int[] to = new int[]{R.id.row_date, R.id.row_name};
// Now create a simple cursor adapter and set it to display
setListAdapter(new SimpleCursorAdapter(this, R.layout.my_list_row, c, from, to));
}
这是我的行布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/row_date" android:layout_width="wrap_content" android:layout_height="fill_parent" />
<TextView android:id="@+id/row_name" android:layout_width="wrap_content" android:layout_height="fill_parent" />
</LinearLayout>
日期实际上以 int 形式存储在 SQLLite 数据库中,因此它显示为整数。
有谁知道从 int 创建日期的方法,所以它不显示为1216544611
(或其他),而是显示为"12/11/2009 11:32"
?