我将我的日期以毫秒为单位存储到我的数据库中。稍后,我尝试从数据库中加载它,并使用 SimpleCursorAdapter 将其加载到文本视图中。但是,每次我调用它时,我都会将毫秒返回为字符串,因此当我将它绑定到文本视图时,我看到的不是正确的格式,而是毫秒。
变量:
public static final String COL_ID = "_id";
public static final String COL_DATE = "date";
public static final String COL_CONTENT = "content";
public static final String COL_IMPORTANT = "important";
private static final int INDEX_ID = 0;
public static final int INDEX_DATE = INDEX_ID + 1;
public static final int INDEX_CONTENT = INDEX_ID + 2;
public static final int INDEX_IMPORTANT = INDEX_ID+ 3;
在数据库适配器中创建函数:
public void createEvent(long day, String name, boolean important) {
ContentValues values = new ContentValues();
values.put(COL_DATE, day);
values.put(COL_CONTENT, name);
values.put(COL_IMPORTANT, important ? 1 : 0);
mDb.insert(TABLE_NAME, null, values);
}
建表查询:
private static final String DATABASE_CREATE =
"CREATE TABLE if not exists " + TABLE_NAME + " ( " +
COL_ID + " INTEGER PRIMARY KEY autoincrement, " +
COL_DATE + " INTEGER, " +
COL_CONTENT + " TEXT, " +
COL_IMPORTANT + " INTEGER );";
我的活动电话:
mDbAdapter = new EventsDbAdapter(this);
mDbAdapter.open();
Cursor cursor = mDbAdapter.fetchAllEvents();
String[] from = new String[] {EventsDbAdapter.COL_DATE, EventsDbAdapter.COL_CONTENT};
int[] to = new int[] {R.id.event_list_row_dayTextView, R.id.event_list_row_dataTextView};
mCursorAdapter = new EventsSimpleCursorAdapter(
CalendarActivity.this,
R.layout.event_feed_item_row,
cursor,
from,
to,
0);
mListView.setAdapter(mCursorAdapter);
肥皂起泡泡
相关分类