根据模型图像改编一个RecycleView&文字自定义布局 我只需要点击项目 OnClickListener 请帮帮我
FeedItem.java
options="{pagination: false}"
FeedListRowHolder.java
public class FeedItem {
private String title;
private String thumbnail;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumbnail() {
return thumbnail;
}
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}}
MyRecyclerAdapter.java
public class FeedListRowHolder extends RecyclerView.ViewHolder {
protected ImageView thumbnail;
protected TextView title;
Context context;
public FeedListRowHolder(View view) {
super(view);
this.thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
this.title = (TextView) view.findViewById(R.id.title);
}}
我需要代码
public class MyRecyclerAdapter extends RecyclerView.Adapter<FeedListRowHolder> {
private List<FeedItem> feedItemList;
private Context mContext;
public MyRecyclerAdapter(Context context, List<FeedItem> feedItemList) {
this.feedItemList = feedItemList;
this.mContext = context;
}
@Override
public FeedListRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row, null);
FeedListRowHolder mh = new FeedListRowHolder(v);
return mh;
}
@Override
public void onBindViewHolder(FeedListRowHolder feedListRowHolder, int i) {
FeedItem feedItem = feedItemList.get(i);
Picasso.with(mContext).load(feedItem.getThumbnail())
.error(R.drawable.list)
.placeholder(R.drawable.info)
.into(feedListRowHolder.thumbnail);
}
@Override
public int getItemCount() {
return (null != feedItemList ? feedItemList.size() : 0);
}}
答案 0 :(得分:0)
这是你想要的???
@Nullable
private OnItemClickListener listener;
public void setOnItemClickListener(OnItemClickListener listener) {
if (null != listener) {
this.listener = listener;
}
}
public interface OnItemClickListener {
void onClick(FeedItem feedItem, int position);
}
@Override
public void onBindViewHolder(FeedListRowHolder feedListRowHolder, int i) {
FeedItem feedItem = feedItemList.get(i);
Picasso.with(mContext).load(feedItem.getThumbnail())
.error(R.drawable.list)
.placeholder(R.drawable.info)
.into(feedListRowHolder.thumbnail);
feedListRowHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onClick(item, position);
}
}
});
}