a
554325746@qq.com
2020-01-13 7171bbcdb2859ea93f3af69d817243752b08314a
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
package com.mcivicm.editablespinner;
 
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
 
import java.util.List;
 
/**
 * 可编辑下拉框适配器
 */
 
public abstract class EditableSpinnerAdapter<T> extends BaseAdapter {
    private List<T> list;
    private Context context;
    private int itemLayout;
 
    public EditableSpinnerAdapter(Context context, List<T> list, int itemLayout) {
        this.context = context;
        this.list = list;
        this.itemLayout = itemLayout;
    }
 
    @Override
    public int getCount() {
        return list.size();
    }
 
    @Override
    public T getItem(int position) {
        return list.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = createItemLayout(parent);
        }
        this.bindView(position, convertView, parent, getItem(position));
        return convertView;
    }
 
    /**
     * 获取视图
     *
     * @param position
     * @param convertView
     * @param parent
     * @param t
     * @return
     */
    public abstract View bindView(int position, @NonNull View convertView, ViewGroup parent, T t);
 
    /**
     * 获取显示在输入框的字符串
     *
     * @param position
     * @return
     */
    public abstract String getDisplayString(int position);
 
    public Object getViewHolder(View view) {
        return view;
    }
 
    private View createItemLayout(ViewGroup parent) {
        View v = LayoutInflater.from(this.context).inflate(itemLayout, parent, false);
        v.setTag(getViewHolder(v));
        return v;
    }
}