擦!RecyclerView的适配器确实比listview的简单些,因为tag都做了封装了

网友投稿 835 2022-09-11

擦!RecyclerView的适配器确实比listview的简单些,因为tag都做了封装了

擦!RecyclerView的适配器确实比listview的简单些,因为tag都做了封装了

RecyclerView

package com.mine.project.function.adapter;import android.content.Context;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.RatingBar;import android.widget.TextView;import com.mine.project.R;import com.mine.project.function.domain.CommentInfo;import java.util.ArrayList;import java.util.List;/** * Created by wy on 2017/7/8. */public class PadGradeAdpter extends RecyclerView.Adapter { private List objects = new ArrayList(); private Context context; private LayoutInflater layoutInflater; public PadGradeAdpter(Context context, List objects) { super(); this.context = context; this.layoutInflater = LayoutInflater.from(context); this.objects = objects; } public CommentInfo getItem(int position) { return objects.get(position); } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { ViewHolder holder = new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_padgrade, parent, false)); return holder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { initializeViews((CommentInfo) getItem(position), holder);// objects=(CommentInfo) getItem(position); } @Override public int getItemCount() { return objects.size(); } private void initializeViews(CommentInfo object, ViewHolder holder) { //TODO implement holder.tvPadGradeTime.setText(object.getCommentTime() + ""); holder.rbOrderDetailXingxing.setRating((float) object.getScore()); holder.tvPadGradeContent.setText(object.getContent() + ""); } protected class ViewHolder extends RecyclerView.ViewHolder { private TextView tvPadGradeTime; private RatingBar rbOrderDetailXingxing; private TextView tvPadGradeContent; public ViewHolder(View view) { super(view); tvPadGradeTime = (TextView) view.findViewById(R.id.tv_padGradeTime); rbOrderDetailXingxing = (RatingBar) view.findViewById(R.id.rb_order_detail_xingxing1); tvPadGradeContent = (TextView) view.findViewById(R.id.tv_padGradeContent); } }}

listview

package com.mine.project.function.adapter;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.RatingBar;import android.widget.TextView;import com.mine.project.R;import com.mine.project.function.domain.CommentInfo;import java.util.ArrayList;import java.util.List;public class ItemPadgradeAdapter extends BaseAdapter { private List objects = new ArrayList(); private Context context; private LayoutInflater layoutInflater; public ItemPadgradeAdapter(Context context, List objects) { this.context = context; this.layoutInflater = LayoutInflater.from(context); this.objects = objects; } @Override public int getCount() { return objects.size(); } @Override public CommentInfo getItem(int position) { return objects.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = layoutInflater.inflate(R.layout.item_padgrade, null); convertView.setTag(new ViewHolder(convertView)); } initializeViews((CommentInfo) getItem(position), (ViewHolder) convertView.getTag()); return convertView; } private void initializeViews(CommentInfo object, ViewHolder holder) { //TODO implement holder.tvPadGradeTime.setText(object.getCommentTime() + ""); holder.rbOrderDetailXingxing.setRating((float) object.getScore()); holder.tvPadGradeContent.setText(object.getContent() + ""); } protected class ViewHolder { private TextView tvPadGradeTime; private RatingBar rbOrderDetailXingxing; private TextView tvPadGradeContent; public ViewHolder(View view) { tvPadGradeTime = (TextView) view.findViewById(R.id.tv_padGradeTime); rbOrderDetailXingxing = (RatingBar) view.findViewById(R.id.rb_order_detail_xingxing1); tvPadGradeContent = (TextView) view.findViewById(R.id.tv_padGradeContent); } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:简单地判断判断两矩形相交/重叠 C#(判断两个矩形相交)
下一篇:EasyCVR程序启动后,流量统计在配置中修改未能生效的问题修复
相关文章

 发表评论

暂时没有评论,来抢沙发吧~