mac
2023-11-30 8231d2af7893e221d90c71bd5dec4cf3f2f1f0ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.hdl.photovoltaic.ui.adapter;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
 
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
 
import com.hdl.photovoltaic.R;
 
import java.util.List;
 
public class LanguageAdapter extends RecyclerView.Adapter<LanguageAdapter.MyViewHolder> {
 
 
    private List<ItemData> mList;
    private final Context mContext;
    private OnclickListener noOnclickListener;//点击了的监听器
 
    public LanguageAdapter(List<ItemData> list, Context context) {
 
        this.mList = list;
        this.mContext = context;
    }
 
    @NonNull
    @Override
    public LanguageAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
 
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_language, parent, false);
        return new LanguageAdapter.MyViewHolder(view);
    }
 
    @Override
    public void onBindViewHolder(@NonNull LanguageAdapter.MyViewHolder holder, int position) {
        ItemData itemData = this.mList.get(position);
        holder.item_lift_name_tv.setText(itemData.getTitle());
        holder.item_lift_name_tv.setTextColor(mContext.getColor(R.color.text_90000000));
        holder.item_right_icon_iv.setBackground(null);
        if (itemData.isState()) {
            holder.item_lift_name_tv.setTextColor(mContext.getColor(R.color.text_245EC3));
            holder.item_right_icon_iv.setBackground(mContext.getResources().getDrawable(R.drawable.select_state));
        }
        if (position == this.mList.size() - 1) {
            holder.item_bottom_line_v.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noOnclickListener != null) {
                    noOnclickListener.onClick(holder.getAdapterPosition(), itemData);
                }
            }
        });
 
    }
 
    @Override
    public int getItemCount() {
        return this.mList == null ? 0 : this.mList.size();
    }
 
 
    public void setList(List<ItemData> list) {
        this.mList = list;
    }
 
    public void setNoOnclickListener(OnclickListener onclickListener) {
        this.noOnclickListener = onclickListener;
    }
    /**
     * 一行布局容器
     */
    static class MyViewHolder extends RecyclerView.ViewHolder {
 
 
        public TextView item_lift_name_tv;
 
        public ImageView item_right_icon_iv;
        public View item_bottom_line_v;
 
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            item_lift_name_tv = itemView.findViewById(R.id.item_lift_name_tv);
            item_right_icon_iv = itemView.findViewById(R.id.item_right_icon_iv);
            item_bottom_line_v = itemView.findViewById(R.id.item_bottom_line_v);
        }
    }
 
    public interface OnclickListener {
        void onClick(int position, ItemData itemData);
    }
 
    public static class ItemData {
 
        private String title;
        private boolean state;
 
        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;
        }
 
 
    }
 
}