【发布时间】:2015-02-11 13:01:19
【问题描述】:
所以我有一个函数:
adapter =new SimpleCursorAdapter(this,R.layout.rating,cu,new String[]{"Title","Fav"}, new int[]{R.id.text1,R.id.bt_rating},CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
//added in last update
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){
/** Binds the Cursor column defined by the specified index to the specified view */
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
if(view.getId() == R.id.bt_rating){
String favorites=cursor.getString(cursor.getColumnIndex("Fav")).toString();
if(favorites.equals("Filled"))
{
((CheckBox)view).setChecked(true);
}
else
{
((CheckBox)view).setChecked(false);
}
((CheckBox)view).setTag(cursor.getInt(cursor.getColumnIndex("_id")));
//((CheckBox)view).setOnCheckedChangeListener(myCheckChangList);
return true; //true because the data was bound to the view
}
return false;
}
});
因为我有一个带有复选框按钮和文本视图的列表视图,所以我告诉 viewbinder 检查复选框值是否已填充(在数据库的 fav 列中)然后它应该检查复选框并将其设置为标签,以便我可以稍后调用它并对其进行处理,如果它为空,它将保持复选框未选中..这工作正常,但由于我需要对数据进行其他工作,我正在尝试创建自己的简单光标适配器......和 ovveride getview() 方法并将之前的工作转化为 public View getView(int arg0, View view, ViewGroup vg) 函数但是不知道怎么做..
【问题讨论】:
标签: android listview simplecursoradapter