package com.hdl.photovoltaic.widget.adapter; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.config.UserConfigManage; import java.util.List; public class ListDialogAdapter extends RecyclerView.Adapter { private List mList; private final Context mContext; private ListDialogAdapter.OnclickListener itemOnclickListener;//点击了的监听器 public ListDialogAdapter(List list, Context context) { this.mList = list; this.mContext = context; } @NonNull @Override public ListDialogAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.diaog_list_line, parent, false); return new ListDialogAdapter.MyViewHolder(view); } @Override public void onBindViewHolder(@NonNull ListDialogAdapter.MyViewHolder holder, int position) { ListDialogAdapter.DialogItemData itemData = this.mList.get(position); holder.list_item_title_tv.setText(itemData.getTitle()); holder.list_item_title_tv.setTextColor(mContext.getColor(R.color.text_50FFFFFF)); if (itemData.isState()) { holder.list_item_title_tv.setTextColor(mContext.getColor(R.color.text_FFFFFFFF)); } if (position == this.mList.size() - 1) { holder.list_item_line_v.setVisibility(View.GONE); } holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (itemOnclickListener != null) { itemOnclickListener.onClick(holder.getAdapterPosition(), itemData); } } }); } @Override public int getItemCount() { return this.mList == null ? 0 : this.mList.size(); } public void setList(List list) { this.mList = list; } public void setItemOnclickListener(ListDialogAdapter.OnclickListener onclickListener) { this.itemOnclickListener = onclickListener; } /** * 一行布局容器 */ static class MyViewHolder extends RecyclerView.ViewHolder { public TextView list_item_title_tv; public View list_item_line_v; public MyViewHolder(@NonNull View itemView) { super(itemView); list_item_title_tv = itemView.findViewById(R.id.list_item_title_tv); list_item_line_v = itemView.findViewById(R.id.list_item_line_v); } } public interface OnclickListener { void onClick(int position, ListDialogAdapter.DialogItemData itemData); } public static class DialogItemData { private String title; private boolean state; //app当前语言 private String language = UserConfigManage.getInstance().getCurrentAppLanguage(); public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getTitle() { return title == null ? "" : title; } public void setTitle(String title) { this.title = title; } public boolean isState() { return state; } public void setState(boolean state) { this.state = state; } } }