|
|
|
@ -2,6 +2,7 @@ package com.android.activity.adapter;
|
|
|
|
|
|
|
|
|
|
import static android.content.ContentValues.TAG;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
@ -29,6 +30,9 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
|
|
|
|
|
protected final ArrayList<Good> mData;
|
|
|
|
|
private RecyclerView mList;
|
|
|
|
|
Context context;
|
|
|
|
|
private OnItemClickListener mOnItemClickListener;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StaggerAdapter(ArrayList<Good> mData, Context context) {
|
|
|
|
|
Log.d("TAG", "StaggerAdapter: ");
|
|
|
|
@ -54,9 +58,14 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
|
|
|
|
|
//绑定holder,一般用来设置数据
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
|
|
|
|
|
|
|
|
|
|
Log.e("TAG", "onBindViewHolder-position"+position );
|
|
|
|
|
String strTvTitle;
|
|
|
|
|
String strTvCount;
|
|
|
|
|
String imageUrl;
|
|
|
|
|
holder.setmPosition(position);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mData.get(position) != null){
|
|
|
|
|
strTvTitle = mData.get(position).getContent();
|
|
|
|
@ -65,6 +74,8 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
|
|
|
|
|
Log.d("TAG", "Title:"+strTvTitle);
|
|
|
|
|
Log.d("TAG", "Count:"+strTvCount);
|
|
|
|
|
Log.e("imageUrl", (String) mData.get(position).getImageUrlList().get(0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
holder.getTvTitle().setText(strTvTitle);
|
|
|
|
|
holder.getTvCount().setText(strTvCount);
|
|
|
|
|
|
|
|
|
@ -82,8 +93,21 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用于监听
|
|
|
|
|
public void setOnItemClickListener(OnItemClickListener listener) {
|
|
|
|
|
//设置一个监听,一个回调的接口
|
|
|
|
|
this.mOnItemClickListener = listener;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface OnItemClickListener{
|
|
|
|
|
//条目
|
|
|
|
|
void onItemClick(int position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InnerHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
|
|
private int mPosition;
|
|
|
|
|
private final ImageView mImage;
|
|
|
|
|
private final TextView mContent;
|
|
|
|
|
private final TextView mPrice;
|
|
|
|
@ -96,24 +120,32 @@ public class StaggerAdapter extends RecyclerView.Adapter<StaggerAdapter.InnerHol
|
|
|
|
|
mContent = itemView.findViewById(R.id.tv_content);
|
|
|
|
|
mPrice = itemView.findViewById(R.id.tv_price);
|
|
|
|
|
|
|
|
|
|
itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
//监听
|
|
|
|
|
if (mOnItemClickListener != null) {
|
|
|
|
|
mOnItemClickListener.onItemClick(mPosition);
|
|
|
|
|
}
|
|
|
|
|
public void setData(Good good) {
|
|
|
|
|
//开始设置数据
|
|
|
|
|
mContent.setText(good.getContent());
|
|
|
|
|
mPrice.setText(good.getPrice());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextView getTvTitle() {
|
|
|
|
|
return mContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextView getTvCount() {
|
|
|
|
|
return mPrice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImageView getIvGoods() {
|
|
|
|
|
return mImage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setmPosition(int position){
|
|
|
|
|
this.mPosition=position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// //实现瀑布流效果
|
|
|
|
|
// private void showStagger() {
|
|
|
|
|