赞
踩
- package com.boyou.live.adapter;
-
- import android.content.Context;
- import android.graphics.Typeface;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
-
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
-
- import com.boyou.live.R;
- import com.boyou.live.bean.ChatListBean;
-
- import java.util.List;
-
-
- public class ListAdapter extends RecyclerView.Adapter {
-
-
- Context context;
- List<ChatListBean.DataBean> data;
-
- public ListAdapter(Context context, List<ChatListBean.DataBean> data) {
- this.context = context;
- this.data = data;
- }
-
-
- @NonNull
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-
- switch (viewType) {
- case 0:
- return new ViewHolderOne(View.inflate(context, R.layout.item_chatlist_lb, null));
- case 1:
- return new ViewHolderTwo(View.inflate(context, R.layout.item_chatlist_lb_txt, null));
- }
- return null;
- }
-
- @Override
- public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
- ChatListBean.DataBean dataBean = data.get(position);
-
- String u_name = dataBean.getU_name();
- String chat = dataBean.getChat();
-
- if (holder instanceof ViewHolderOne) {
- int spectator_lv = dataBean.getSpectator_lv();
- ((ViewHolderOne) holder).chatlist_dj_tv.setText(spectator_lv + "");
- ((ViewHolderOne) holder).chatlist_namer_tv.setText(u_name + ":");
- ((ViewHolderOne) holder).chatlist_nr.setText(chat);
- } else if (holder instanceof ViewHolderTwo) {
- ((ViewHolderOne) holder).chatlist_nr_tv.setText(chat);
- }
-
- }
-
-
- @Override
- public int getItemCount() {
- return data.size();
- }
-
- public class ViewHolderOne extends RecyclerView.ViewHolder {
- RelativeLayout chatlist_dj_tv_rl, chatlist_nr_tv_rl;
- TextView chatlist_dj_tv, chatlist_namer_tv, chatlist_nr, chatlist_nr_tv;
-
- public ViewHolderOne(@NonNull View itemView) {
- super(itemView);
- chatlist_dj_tv = itemView.findViewById(R.id.chatlist_dj_tv);
- chatlist_namer_tv = itemView.findViewById(R.id.chatlist_namer_tv);
- chatlist_nr = itemView.findViewById(R.id.chatlist_nr);
- chatlist_dj_tv_rl = itemView.findViewById(R.id.chatlist_dj_tv_rl);
-
- chatlist_nr_tv_rl = itemView.findViewById(R.id.chatlist_nr_tv_rl);
- chatlist_nr_tv = itemView.findViewById(R.id.chatlist_nr_tv);
-
-
- Typeface typeFace = Typeface.createFromAsset(context.getAssets(), "pf_ht_z_j.ttf");
- chatlist_dj_tv.setTypeface(typeFace);
- chatlist_namer_tv.setTypeface(typeFace);
- chatlist_nr.setTypeface(typeFace);
-
- chatlist_nr_tv.setTypeface(typeFace);
- }
- }
-
- public class ViewHolderTwo extends RecyclerView.ViewHolder {
- TextView chatlist_nr_tv;
-
- public ViewHolderTwo(View itemView) {
- super(itemView);
- chatlist_nr_tv = itemView.findViewById(R.id.chatlist_nr_tv);
-
- Typeface typeFace = Typeface.createFromAsset(context.getAssets(), "pf_ht_z_j.ttf");
- chatlist_nr_tv.setTypeface(typeFace);
- }
- }
- }
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。