Android 正在尝试将adapter.setViewBinder转换为适配器的重写方法中的getview方法
所以我有一个函数:Android 正在尝试将adapter.setViewBinder转换为适配器的重写方法中的getview方法,android,listview,simplecursoradapter,Android,Listview,Simplecursoradapter,所以我有一个函数: 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 Si
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;
}
});
因为我有一个带有复选框按钮和文本视图的listview,所以我告诉viewbinder检查复选框值是否已填充(在数据库的fav列中),然后它应该检查复选框并将其设置为标记,以便我以后可以调用它并处理它,如果它为空,它将保持复选框未选中。。这很好,但由于我需要对数据进行其他工作,我正在尝试创建自己的simplecursor适配器。。。验证getview()方法,并将以前的工作转换为public View getview(int arg0,View View View,ViewGroup vg)函数,但不知道如何实现它。我看到了本教程,它非常棒: 有了这些信息,我完成了我的任务