public class CreditManagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<CreditManager> datas;
private final LayoutInflater mLayoutInflater;
private MyItemClickListener mItemClickListener;
public CreditManager getDataItem(int position) {
return datas == null ? null : datas.get(position);
}
public CreditManagerAdapter(Context mContext, List<CreditManager> mDatas) {
this.mContext = mContext;
this.datas = mDatas;
mLayoutInflater = LayoutInflater.from(mContext);
}
public void update(List<CreditManager> mDatas) {
this.datas = mDatas;
//this.notifyDataSetChanged();
}
public void notifyData(List<CreditManager> mDatas) {
this.datas = mDatas;
this.notifyDataSetChanged();
}
public int getLayout() {
return R.layout.creditmanager_dialog_item;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(getLayout(), parent, false);
RecyclerView.ViewHolder viewHolder = new ViewHolder(v, mItemClickListener);
return viewHolder;
}
/**
* 设置Item点击监听
*
* @param listener
*/
public void setOnItemClickListener(MyItemClickListener listener) {
mItemClickListener = listener;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int p) {
final ViewHolder mHolder = (ViewHolder) holder;
CreditManager data = datas.get(p);
}
@Override
public int getItemCount() {
return datas == null ? 0 : datas.size();
}
public interface MyItemClickListener {
public void OnClickListener(int position);
}
static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private MyItemClickListener mItemClickListener;
ViewHolder(View view, MyItemClickListener mItemClickListener) {
super(view);
ButterKnife.bind(this, view);
this.mItemClickListener = mItemClickListener;
view.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.OnClickListener(getPosition());
}
}
}
}
热门评论
还是 评价下吧 你的程序里面 又一个小小的问题,而不是bug