02 LayoutInflater

(1) LayoutInflater inflater = LayoutInflater.from(getContext());

View itemView = inflater.inflate(R.layout.agenda_item, this);


(2) LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View itemView = inflater.inflate(R.layout.agenda_item, this);


当你为一个 activty 添加一个可见的 view, 并且运行这个activty时,android通常情况下会自动按照下列顺序来触发view的相关事件

onAttachedToWindow
onMeasure
onSizeChanged
onLayout
onDraw
public AdapterView.OnItemClickListener mListener; // // public interface OnItemClickListener { // void onItemClick(int position); // } // public void setOnItemClickListener(OnItemClickListener listener) { // mListener = (AdapterView.OnItemClickListener) listener; // } public MyAdapter(List<DataBean> mlist, Context mcontext) { this.mlist = mlist; this.mcontext = mcontext; } @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View inflate = LayoutInflater.from(mcontext).inflate(R.layout.item, parent, false); ViewHolder holder = new ViewHolder(inflate); return holder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { if (TextUtils.isEmpty(mlist.get(position).getThumbnail_pic_s())&&TextUtils.isEmpty(mlist.get(position).getThumbnail_pic_s03())){ Picasso.get().load(mlist.get(position).getThumbnail_pic_s02()).into(holder.img1); holder.img.setVisibility(View.GONE); holder.img2.setVisibility(View.GONE); holder.tv.setText(mlist.get(position).getTitle()); holder.tv1.setText(mlist.get(position).getAuthor_name()); holder.tv2.setText(mlist.get(position).getCategory()); }else if (TextUtils.isEmpty(mlist.get(position).getThumbnail_pic_s02())) { Picasso.get().load(mlist.get(position).getThumbnail_pic_s()).into(holder.img); Picasso.get().load(mlist.get(position).getThumbnail_pic_s03()).into(holder.img2); holder.img1.setVisibility(View.GONE); holder.tv.setText(mlist.get(position).getTitle()); holder.tv1.setText(mlist.get(position).getAuthor_name()); holder.tv2.setText(mlist.get(position).getCategory()); }else { Picasso.get().load(mlist.get(position).getThumbnail_pic_s()).into(holder.img); Picasso.get().load(mlist.get(position).getThumbnail_pic_s02()).into(holder.img1); Picasso.get().load(mlist.get(position).getThumbnail_pic_s03()).into(holder.img2); holder.tv.setText(mlist.get(position).getTitle()); holder.tv1.setText(mlist.get(position).getAuthor_name()); holder.tv2.setText(mlist.get(position).getCategory()); } holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener != null) { mListener.onItemClick(position); } } });position报红
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值