我的代码不会使用扩展适配器的getView()

时间:2012-03-19 16:53:28

标签: android android-listview listadapter

我想在一个列表视图中列出多个布局记录。为此,我从Web服务获取数据并将其加载到我的自定义VO类Object。然后,它正在处理我的两种行数据。我将它传递给我的适配器,但它没有生成自定义列表视图数据。这是我的代码。

适配器:

public class FeedsAdapter extends ArrayAdapter<VO_BaseFeedHolder> {

    VO_BaseFeedHolder                   _mBaseFeedHolder;
    ArrayList<VO_CDobFeedHolder>        _cDobHolder;
    ArrayList<VO_CRateFeedHolder>       _cRateHolder;
    final Object mLock                  = new Object();
    protected LayoutInflater            _mInflator;
    private static final int TYPE_RATING = 0;
    private static final int TYPE_DOB    = 1;

    public FeedsAdapter(Activity context, ArrayList<VO_BaseFeedHolder> mBaseFeedHolder) {
        super(context, R.layout.dashboard,mBaseFeedHolder);         

        this._mBaseFeedHolder   = mBaseFeedHolder.get(0);
        this._cDobHolder        = _mBaseFeedHolder.dobFeeds;
        this._cRateHolder       = _mBaseFeedHolder.ratingFeeds;
        this._mInflator         = context.getLayoutInflater();
    }

    static class FeedsViewHolder {

        // BIRTHDAY COMPONENTS
        public ImageView _feedIcon;
        public TextView _phrase;
        public TextView _timeStamp;
        public TextView _like;
        public TextView _protobox;
        public boolean _isRating;

    }

    @Override
    public int getCount() {
        synchronized (mLock) {

        }
        return 0;
    };

    @Override
    public int getItemViewType(int position) {
        return TYPE_DOB;
    };

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("IN","IN TO GETVIEW");
        View rowView = convertView;
        FeedsViewHolder fvholder = new FeedsViewHolder();
        int type     = getItemViewType(position);
        if (rowView == null) {
            switch(type) {
            case TYPE_RATING:
                rowView = _mInflator.inflate(R.layout.dashboardfrate, null);
                fvholder._feedIcon = (ImageView) rowView.findViewById(R.id.ratingpic);
                fvholder._phrase   = (TextView) rowView.findViewById(R.id.ratingphrase);
                fvholder._timeStamp= (TextView) rowView.findViewById(R.id.ratingtimestamp);
                fvholder._isRating = true;
                break;
            case TYPE_DOB:
                rowView = _mInflator.inflate(R.layout.dashboardfdob, null);
                //fvholder = new FeedsViewHolder();
                fvholder._feedIcon  = (ImageView) rowView.findViewById(R.id.birthdaypic);
                fvholder._phrase    = (TextView) rowView.findViewById(R.id.birthdayphrase);
                fvholder._like      = (TextView) rowView.findViewById(R.id.birthdaylike);
                fvholder._isRating  = false;                
                break;
            }

            rowView.setTag(fvholder);
        } else {
            fvholder = (FeedsViewHolder) rowView.getTag();
        }

        if(fvholder._isRating == false) {
            Log.i("INTO fvHolder","TRUE");
            VO_CDobFeedHolder _mdobRecord = this._cDobHolder.get(position);
            Log.i("_mDob",_mdobRecord._userid);
            fvholder._phrase.setText("The Record by "+_mdobRecord._userid);
            fvholder._like.setTag(_mdobRecord._userid);
        } else {
            VO_CRateFeedHolder _mRateRecord = this._cRateHolder.get(position);
            fvholder._phrase.setText("RATING COMMENT: "+_mRateRecord._comments);
            fvholder._timeStamp.setText(_mRateRecord._timestamp);
        }
        return rowView;
    }

}

活动:

FeedLoader();
private void FeedLoader() {
             String[] params = new String[] {};
             try {
                this.mvoBaseFeedHolder = new FetchFeedTask().execute(params).get();
                this._collection.add(mvoBaseFeedHolder);
                setListAdapter(new FeedsAdapter(this,this._collection));
            } catch (InterruptedException e) {
                Log.i("INTURRPTED",e.toString());
            } catch (ExecutionException e) {
                Log.i("Execution",e.toString());
            }
     }

VO_BaseFeedHolder在这里:

public class VO_BaseFeedHolder {

    ArrayList<VO_CDobFeedHolder> dobFeeds;
    ArrayList<VO_CRateFeedHolder> ratingFeeds;

    public VO_BaseFeedHolder(ArrayList<VO_CDobFeedHolder> _dobObject,ArrayList<VO_CRateFeedHolder> _rateObject) {
        dobFeeds        =  _dobObject;
        ratingFeeds     =  _rateObject;
    }

}

VO_CDobFeedHolder:

public class VO_CDobFeedHolder {

    String _userid, _date;

    public VO_CDobFeedHolder(String userid,String date) {
        this._userid    = userid;
        this._date      = date;
    }
}

VO_CRateFeedHolder:

public class VO_CRateFeedHolder {

    final String _userid,_projectid,_responder,_stars,_comments,_timestamp;

    public VO_CRateFeedHolder(String userid, String projectid,String responder,String stars,String comments,String timestamp) {
        this._userid = userid;
        this._projectid = projectid;
        this._responder = responder;
        this._stars = stars;
        this._comments = comments;  
        this._timestamp = timestamp;
    }

}

任何人都可以让我了解这种情况。需要帮助!

1 个答案:

答案 0 :(得分:3)

因为你的

  @Override
public int getCount() {
    synchronized (mLock) {

    }
    return 0;
};

正在返回0。让我们返回您需要显示的项目数