| | |
| | | package com.dayu.recharge.adapter; |
| | | |
| | | import android.content.Context; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.BaseAdapter; |
| | |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.databinding.DataBindingUtil; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.dayu.recharge.R; |
| | | import com.dayu.recharge.databinding.ItemRechargeBinding; |
| | | import com.dayu.recharge.databinding.ItemNoMoreBinding; |
| | | import com.dayu.recharge.databinding.ItemRechargeBinding; |
| | | import com.dayu.recharge.dbBean.RechargeBean; |
| | | import com.dayu.recharge.dbBean.UserCardBean; |
| | | import com.dayu.recharge.utils.DateUtil; |
| | | |
| | | import java.util.List; |
| | |
| | | * Created by zuoxiao on 2018/12/24. |
| | | */ |
| | | |
| | | public class RechargeAdapter extends BaseAdapter { |
| | | public class RechargeAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder> { |
| | | |
| | | List<RechargeBean> rechargeList; |
| | | Context mContext; |
| | |
| | | this.rechargeList = rechargeList; |
| | | } |
| | | |
| | | |
| | | @NonNull |
| | | @Override |
| | | public int getCount() { |
| | | if (rechargeList == null) { |
| | | return 0; |
| | | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| | | if (viewType == VIEW_TYPE_EMPTY) { |
| | | ItemNoMoreBinding emptyView = DataBindingUtil.inflate((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE), R.layout.item_no_more, parent, false); |
| | | return new ViewHolderEmpty(emptyView); |
| | | } else { |
| | | ItemRechargeBinding binding = DataBindingUtil.inflate((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE), R.layout.item_recharge, parent, false); |
| | | return new ViewHolder(binding); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| | | if (holder instanceof ViewHolder) { |
| | | if (rechargeList.size() > 0) { |
| | | ((ViewHolder) holder).getBinding().userName.setText("用户名:" + rechargeList.get(position).getUserName()); |
| | | ((ViewHolder) holder).getBinding().userNo.setText("用户编号:" + rechargeList.get(position).getInitPeasantCode()); |
| | | ((ViewHolder) holder).getBinding().morny.setText("充值金额:" + rechargeList.get(position).getMorny()); |
| | | ((ViewHolder) holder).getBinding().date.setText("日期:" + DateUtil.dateToStamp(rechargeList.get(position).getDate(), DateUtil.type1)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int getItemCount() { |
| | | //同时这里也需要添加判断,如果mData.size()为0的话,只引入一个布局,就是emptyView |
| | | // 那么,这个recyclerView的itemCount为1 |
| | | if (rechargeList.size() == 0) { |
| | | return 1; |
| | | } |
| | | return rechargeList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getItem(int position) { |
| | | return position; |
| | | } |
| | | |
| | | @Override |
| | | public long getItemId(int position) { |
| | | return position; |
| | | } |
| | | |
| | | @Override |
| | | public View getView(int position, View convertView, ViewGroup parent) { |
| | | ViewHolder holder = null; |
| | | if (convertView == null) { |
| | | holder = new ViewHolder(); |
| | | convertView = View.inflate(mContext, R.layout.item_recharge, null); |
| | | holder.userName = (TextView) convertView.findViewById(R.id.userName); |
| | | holder.userNo = (TextView) convertView.findViewById(R.id.userNo); |
| | | holder.morny = (TextView) convertView.findViewById(R.id.morny); |
| | | holder.date = (TextView) convertView.findViewById(R.id.date); |
| | | |
| | | convertView.setTag(holder); |
| | | public int getItemViewType(int position) { |
| | | if (rechargeList.size() == 0) { |
| | | return VIEW_TYPE_EMPTY; |
| | | } else { |
| | | holder = (ViewHolder) convertView.getTag(); |
| | | return VIEW_TYPE_ITEM; |
| | | } |
| | | holder.userName.setText("用户名:" + rechargeList.get(position).getUserName()); |
| | | holder.userNo.setText("身份证号:" + rechargeList.get(position).getUserId()); |
| | | holder.morny.setText("充值金额:" + rechargeList.get(position).getMorny()); |
| | | holder.date.setText("日期:" + DateUtil.dateToStamp(rechargeList.get(position).getDate(), DateUtil.type1)); |
| | | return convertView; |
| | | } |
| | | |
| | | class ViewHolder { |
| | | |
| | | TextView userName; |
| | | TextView userNo; |
| | | TextView morny; |
| | | TextView date; |
| | | static class ViewHolder extends RecyclerView.ViewHolder { |
| | | ItemRechargeBinding mBinding; |
| | | |
| | | public ItemRechargeBinding getBinding() { |
| | | return mBinding; |
| | | } |
| | | |
| | | public void setBinding(ItemRechargeBinding binding) { |
| | | this.mBinding = binding; |
| | | } |
| | | |
| | | public ViewHolder(ItemRechargeBinding itemView) { |
| | | super(itemView.getRoot()); |
| | | this.mBinding = itemView; |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | } |