1

我有一个扩展的 SimpleCrussorAdopter,它根据某些条件返回两个视图之一。

 public ListAdapter(Context context, int layout, Cursor c, String[] from,
        int[] to, int flags) {
     super(context, layout, c, from, to, flags);

 }
  @Override
  public int getViewTypeCount() {
     return 2;
}


 @Override
  public int getItemViewType(int position) {

   if(condition == true) return 1;
    else return 0;
  }


  @Override

     public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View rowView ;

     if( getItemViewType(position) == 1){

    if(convertView == null){
        convertView = inflater.inflate(R.layout.row1, parent, false);
          rowView = (View)convertView;
      }else
      {
         rowView = (View)convertView;
        }

  }else
     {
        //inflate and the second view row2, in the above manner
 } return rowView;
}

下面是视图活页夹:

  adapter.setViewBinder(new PuzzleListAdapter.ViewBinder() {
                public boolean setViewValue(View view, Cursor cursor, int columnIndex)         {
                    int percent =    cursor.getColumnIndex(PuzzleDatabase.KEY_PUZZLE_PERCENT_COMPLETED);

                    if (percent == columnIndex) {

                        ProgressBar pbar = (ProgressBar) view ;
                        int progress = cursor.getInt(columnIndex);
                        pbar.setProgress(progress);
                        return true;
                    }
                    return false;
                }
            });  

此视图卷取器与 SimpleCrussorAdapter 对象完美配合。

可能是什么问题呢

问题 1:如果我扩展 SimpleCrussorAdaptor,它无法使用其父类功能将 crossor col 列与视图绑定。

问题 2:使用扩展的 SimpleCrussorAdaptor 自定义视图活页夹也无法正常工作。

我是不是错过了什么。

4

0 回答 0