码迷,mamicode.com
首页 > 其他好文 > 详细

Fragment 之 PagerAdapter

时间:2016-06-25 10:58:38      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

package com.edaixi.main.adapter;


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;



import java.util.List;

/**
 * Provide views to RecyclerView with data from mDataSet.
 */
public class CommentAdapter extends PagerAdapter {

    private List<AppraiseBean> appraiseBeans;
    private Context context;

    public CommentAdapter(Context context, List<AppraiseBean> appraiseBeans) {
        LogUtil.e("come in staruct");
        this.appraiseBeans = appraiseBeans;
        this.context = context;
    }

    @Override
    public int getCount() {
        return appraiseBeans.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_appraise_list, container, false);

        LogUtil.e("come in adapter");
        AppraiseBean appraiseOption = null;
        if (appraiseBeans.size() > 0)
            appraiseOption = appraiseBeans.get(position);

        TextView tv_appraise_content = (TextView) view.findViewById(R.id.tv_appraise_content);
        TextView tv_appraise_user = (TextView) view.findViewById(R.id.tv_appraise_user);
        TextView tv_appraise_time = (TextView) view.findViewById(R.id.tv_appraise_time);

        if (appraiseBeans != null && appraiseBeans.size() == 3) {
            tv_appraise_content.setLines(2);
            tv_appraise_content.setEllipsize(TextUtils.TruncateAt.valueOf("END"));
        }

        tv_appraise_user.setText(appraiseOption.getUser() + "  " + appraiseOption.getTel());
        tv_appraise_content.setText(appraiseOption.getComment());
        tv_appraise_time.setText(appraiseOption.getCategory() + "  " + appraiseOption.getDate());


        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}

 

Fragment 之 PagerAdapter

标签:

原文地址:http://www.cnblogs.com/spring87/p/5615926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!