Fragment 之 PagerAdapter
Posted 狂奔的小狮子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fragment 之 PagerAdapter相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Android中FragmentPagerAdapter对Fragment的缓存
FragmentPagerAdapter/FragmentStatePagerAdapter/PagerAdapter