gpt4 book ai didi

java - Android:在 ListView 中将整数读取为字符串

转载 作者:行者123 更新时间:2023-11-30 02:58:56 26 4
gpt4 key购买 nike

我目前有一个包含从 sqlite 数据库填充的 listView 的应用程序。 ListView 包含每个项目的两个 TextView ,一个用于名称,一个用于状态。状态由 0 或 1 显示,如 true 或 false。我想让每个包含数字 0 或 1 的项目作为状态显示打开或关闭。

ListView 的方法:

// 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);
}

我该怎么做呢?

最佳答案

您必须实现 myCursorAdapter 的 setViewValue 方法,以便您可以将 TextView 设置为在 1 或 0 时打开或关闭。

查看this answer举个例子。另外,看看 developer's guide了解更多详情。

关于java - Android:在 ListView 中将整数读取为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22852256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com