wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
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
package MyJar.PickerView;
 
import java.util.ArrayList;
 
/**
 * The simple Array wheel adapter
 * @param <T> the element type
 */
public class ArrayWheelAdapter<T> implements WheelAdapter {
    
    /** The default items length */
    public static final int DEFAULT_LENGTH = 4;
    
    // items
    private ArrayList<T> items;
    // length
    private int length;
 
    /**
     * Constructor
     * @param items the items
     * @param length the max items length
     */
    public ArrayWheelAdapter(ArrayList<T> items, int length) {
        this.items = items;
        this.length = length;
    }
    
    /**
     * Contructor
     * @param items the items
     */
    public ArrayWheelAdapter(ArrayList<T> items) {
        this(items, DEFAULT_LENGTH);
    }
 
    @Override
    public String getItem(int index) {
        if (index >= 0 && index < items.size()) {
            return items.get(index).toString();
        }
        return null;
    }
 
    @Override
    public int getItemsCount() {
        return items.size();
    }
 
    @Override
    public int getMaximumLength() {
        return length;
    }
 
}