yy1717
2020-09-17 1635b1420128b33b3d17e21e92625da651fca11e
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package safeluck.drive.evaluation.adapter;
 
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
 
import java.util.ArrayList;
import java.util.List;
 
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.bean.BaseDataUIBean;
import safeluck.drive.evaluation.fragment.BaseDatasFragment;
 
/**
 * MyApplication2
 * Created by lzw on 2020/1/10. 16:33:13
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
 
public class BaseDataInfoAdapter extends BaseAdapter implements View.OnClickListener {
    private List<BaseDataUIBean> persons = new ArrayList<>();
    private final static String TAG = "anyun_info";
    private Context mContext;
    private Callback mCallback;
    @Override
    public int getCount() {
        return persons.size();
    }
 
    @Override
    public BaseDataUIBean getItem(int i) {
        return persons.get(i);
    }
 
    @Override
    public int getViewTypeCount() {
        return 2;
    }
 
    @Override
    public long getItemId(int i) {
        return i;
    }
 
    @Override
    public int getItemViewType(int position) {
        if (persons.get(position).getType()==0){
            return 0;
        }else{
 
        return 1;
        }
    }
 
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        InfoHodler infoHodler = null;
        MapCarInfoHodler mapCarinfoHodler = null;
 
        switch (getItemViewType(i)){
            case 0:
                if (view == null){
                    view = LayoutInflater.from(mContext).inflate(R.layout.gps_info_item,null);
                    infoHodler = new InfoHodler();
                    infoHodler.name = view.findViewById(R.id.text_check_info);
                    view.setTag(infoHodler);
                }else{
                    infoHodler = (InfoHodler) view.getTag();
                }
                infoHodler.name.setText(getItem(i).getDes());
                infoHodler.name.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().
                        getDrawable(getItem(i).getRes_id()),null,null,null);
                infoHodler.name.setCompoundDrawablePadding(10);
                break;
            default:
                Log.i(TAG,"Defalut");
                if (view == null){
                    view = LayoutInflater.from(mContext).inflate(R.layout.map_car_info_update,null);
                    mapCarinfoHodler = new MapCarInfoHodler();
                    mapCarinfoHodler.name = view.findViewById(R.id.tv_map_name);
                    mapCarinfoHodler.version = view.findViewById(R.id.tv_version);
                    mapCarinfoHodler.btn = view.findViewById(R.id.btn_update_map_car);
                    view.setTag(mapCarinfoHodler);
                }else{
                    mapCarinfoHodler = (MapCarInfoHodler) view.getTag();
                }
                mapCarinfoHodler.btn.setOnClickListener(this);
                mapCarinfoHodler.btn.setTag(i);
                mapCarinfoHodler.name.setText(getItem(i).getDes());
                mapCarinfoHodler.name.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().
                        getDrawable(getItem(i).getRes_id()),null,null,null);
                mapCarinfoHodler.name.setCompoundDrawablePadding(10);
 
                mapCarinfoHodler.btn.setText(getItem(i).getBtn_txt());
                mapCarinfoHodler.version.setText(getItem(i).getVersion());
 
 
                break;
        }
 
 
 
        return view;
    }
 
    public BaseDataInfoAdapter(Context mContext) {
        this.mContext = mContext;
    }
    /**
     * //先清掉原来的所有数据再添加新加进来所有的数据
     * @param ps
     */
    public void addAll(List<BaseDataUIBean> ps){
        persons.clear();//先清掉原来的所有数据
        persons.addAll(ps);//再添加新加进来所有的数据
        notifyDataSetChanged();//刷新界面
    }
 
    @Override
    public void onClick(View v) {
        if (mCallback != null){
            mCallback.click(v);
        }
    }
 
    public void setCallback(Callback call) {
        this.mCallback = call;
    }
 
    /**
     * 自定义接口,用于回调按钮点击事件到Fragment、Activity
     */
    public interface Callback{
        void click(View view);
    }
 
    static class InfoHodler {
 
 
        public TextView name;//姓名
 
 
 
 
 
    }
    static class MapCarInfoHodler {
 
 
        public TextView name;//姓名
        public TextView version;//姓名
    public Button btn;
 
 
 
 
    }
 
}