【发布时间】:2014-04-04 02:07:59
【问题描述】:
我目前有一个包含从 sqlite 数据库填充的 listView 的应用程序。 ListView 包含每个项目的两个文本视图,一个用于名称,一个用于状态。状态由 0 或 1 显示,例如 true 或 false。我想让每个包含数字 0 或 1 的项目作为状态显示为打开或关闭。
列表视图的方法:
// Return all data in the database.
public Cursor getAllRows() {
String where = null;
Cursor c = ourDatabase.query(true, DATABASE_TABLE, ALL_KEYS, where,
null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
// also added
// Get a specific row (by rowId)
public Cursor getRow(long rowId) {
String where = KEY_ROWID + "=" + rowId;
Cursor c = ourDatabase.query(true, DATABASE_TABLE, ALL_KEYS, where,
null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
这是我的 listView 代码:
private void loadListView() {
// TODO Auto-generated method stub
Locker getList = new Locker(this);
getList.open();
Cursor cursor = getList.getAllRows();
startManagingCursor(cursor);
// setup mapping
String[] fromFieldNames = new String[] { getList.KEY_LOCKERNUMBER,
getList.KEY_STATUS };
int[] toViewIDs = new int[] { R.id.tvLockerNumber, R.id.tvSatus };
// create adapter
SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,
R.layout.itemlayout, cursor, fromFieldNames, toViewIDs);
// set the adapter
ListView myList = (ListView) findViewById(R.id.lvInfo);
myList.setAdapter(myCursorAdapter);
}
我该怎么做?
【问题讨论】:
-
"我想让每个包含数字 0 或 1 的项目作为状态显示为打开或关闭。"你说的开放还是封闭是什么意思?您是在谈论不同的布局吗?
-
目前在列表视图中,它从我的数据库中获取状态变量,它可以是 0 或 1。我希望我的列表视图能够解释这些整数并在 textview 上显示为打开或关闭。
标签: java android sqlite listview android-listview