我有点卡在android中的viewbinders上
这是我的代码:
public void displayAllAlerts() {
Cursor mCursor = mDbAdapter.fetchAllAlerts();
//Bind Columns
String[] columns = new String[] {
DbAdapter.KEY_ID,
DbAdapter.KEY_PLACE,
DbAdapter.KEY_LONG,
DbAdapter.KEY_LAT,
DbAdapter.KEY_STATUS
};
int[] to = new int[] {
R.id.txtId,
R.id.txtPlace,
R.id.txtLong,
R.id.txtLat,
R.id.tglBtnAlert
};
mSimpleCursorAdapter = new SimpleCursorAdapter(
this,
R.layout.layout_lvrow,
mCursor,
columns,
to,
0);
ListView lvAlerts = (ListView) findViewById(R.id.lvAlerts);
lvAlerts.setAdapter(mSimpleCursorAdapter);
}
问题是“DbAdapter.key_status”在我的数据库中被格式化为 int,但不知何故我必须将其更改为布尔值,因为这是我的切换按钮的状态。
我知道我必须使用 .setViewBinder,但我不知道要开始。
我从一些教程中尝试了以下方法,但它不起作用:
mSimplecursorAdapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 5) {
String strBool = aCursor.getString(aColumnIndex);
ToggleButton tb = (Togglebutton) aView;
if (strBool=="0") {
tb.setChecked = false;
}else{
tb.setChecked = true;
}
return true;
}
return false;
}
提前致谢
(也尝试过使用android的开发者网站,但这让我很头疼)