mac
2024-06-05 c7eeb5c6bc5d1cba44e92761d4be67f97f7c23aa
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
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.TextView;
 
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
 
import com.hdl.photovoltaic.R;
 
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 历史记录适配器
 */
public class SearchHistoryAdapter extends RecyclerView.Adapter<SearchHistoryAdapter.MyViewHolder> {
 
    List<String> mList;
 
    Context mContext;
 
    OnClickListener mOnclickListener;
 
    public SearchHistoryAdapter(Context context) {
 
        this.mContext = context;
    }
 
    @NonNull
    @Override
    public SearchHistoryAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history_title, parent, false);
        return new MyViewHolder(view);
    }
 
    @Override
    public void onBindViewHolder(@NonNull SearchHistoryAdapter.MyViewHolder holder, int position) {
        String history_title = this.mList.get(position);
 
        holder.history_title_tv.setText(history_title);
        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (mOnclickListener != null) {
                        mOnclickListener.onClick((int) holder.itemView.getTag(), history_title);
                    }
                } catch (Exception ignored) {
                }
            }
        });
 
    }
 
    @Override
    public int getItemCount() {
        return this.mList == null ? 0 : this.mList.size();
    }
 
    public void setOnclickListener(OnClickListener onClickListener) {
        this.mOnclickListener = onClickListener;
    }
 
    public void setList(List<String> newData) {
        if (this.mList == null) {
            this.mList = new ArrayList<>();
        } else {
            this.mList.clear();
        }
 
        this.mList.addAll(newData);
        notifyDataSetChanged();
    }
 
    public interface OnClickListener {
        void onClick(int position, String title);
 
    }
 
    static class MyViewHolder extends RecyclerView.ViewHolder {
 
 
        public TextView history_title_tv;
 
 
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            history_title_tv = itemView.findViewById(R.id.history_title_tv);
        }
    }
}