尝试将适配器转换为适配器Overriden方法中的getView方法



所以我有一个函数:

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

因为我有一个带有复选框按钮和textView的listView,所以我告诉ViewBinder检查复选框值是否已填充(在数据库中的" fav"列中),因此它应该检查复选框并将其设置为标签,以便我i稍后可以打电话给它并进行处理,如果它是空的,它将保持复选框。getView()方法并将先前的工作转换为公共视图getView(int arg0,view view,viewgroup vg)函数,但不知道该怎么做。

我看到了本教程,很棒:

https://dl.google.com/googleio/2010/android-world-of-listview-android.pdf

有了这些信息,我完成了任务。

最新更新