1+ package com .dvinfosys .widgets .AutoSelect ;
2+
3+ import android .content .Context ;
4+ import android .support .annotation .NonNull ;
5+ import android .view .LayoutInflater ;
6+ import android .view .View ;
7+ import android .view .ViewGroup ;
8+ import android .widget .ArrayAdapter ;
9+ import android .widget .TextView ;
10+
11+ import com .dvinfosys .widgets .R ;
12+
13+ import java .util .ArrayList ;
14+
15+ public class ASDefaultAdapter extends ArrayAdapter <String > {
16+
17+ private ArrayList <String > items ;
18+ private Context context ;
19+
20+ // Things to provide proper cell configuration comparing to configuration of picker box element
21+ // Any custom implementation doesn't need this three vars
22+ private int cellHeight ;
23+ private int cellTextSize ;
24+ private ASDefaultPickerBox dsPickerBoxDefault ;
25+
26+ ASDefaultAdapter (Context context , int textViewResourceId , ArrayList <String > stringItems , Integer cellHeight , Integer cellTextSize ) {
27+ super (context , textViewResourceId , stringItems );
28+ this .items = stringItems ;
29+ this .context = context ;
30+ this .cellHeight = cellHeight ;
31+ this .cellTextSize = cellTextSize ;
32+ }
33+
34+ void setDsPickerBoxDefault (ASDefaultPickerBox dsPickerBoxDefault ) {
35+ this .dsPickerBoxDefault = dsPickerBoxDefault ;
36+ }
37+
38+ void setCellHeight (Integer cellHeight ) {
39+ this .cellHeight = cellHeight ;
40+ }
41+
42+ void setCellTextSize (Integer cellTextSize ) {
43+ this .cellTextSize = cellTextSize ;
44+ }
45+
46+ @ Override
47+ public long getItemId (int position ) {
48+ return position ;
49+ }
50+
51+ @ Override
52+ public boolean hasStableIds () {
53+ return true ;
54+ }
55+
56+ @ Override
57+ public int getCount () {
58+ return items .size ();
59+ }
60+
61+ @ NonNull
62+ @ Override
63+ public View getView (int position , View convertView , @ NonNull ViewGroup parent ) {
64+ ASDefaultAdapter .ViewHolder holder ;
65+
66+ if (null == convertView ) {
67+ LayoutInflater vi = (LayoutInflater ) context .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
68+ assert vi != null ;
69+ convertView = vi .inflate (R .layout .as_default_list_item , parent , false );
70+ holder = new ASDefaultAdapter .ViewHolder ();
71+ holder .text = convertView .findViewById (R .id .ds_default_cell_text );
72+ convertView .setTag (holder );
73+ } else {
74+ holder = (ViewHolder ) convertView .getTag ();
75+ }
76+
77+ if (null != holder ) {
78+ holder .text .setText (items .get (position ));
79+
80+ if (cellHeight > 0 )
81+ convertView .setMinimumHeight (cellHeight );
82+
83+ if (cellTextSize > 0 )
84+ holder .text .setTextSize (cellTextSize );
85+
86+ if (null != this .dsPickerBoxDefault )
87+ convertView .setPadding (dsPickerBoxDefault .getPaddingLeft (), dsPickerBoxDefault .getPaddingTop (),
88+ dsPickerBoxDefault .getPaddingRight (), dsPickerBoxDefault .getPaddingBottom ());
89+ }
90+ return convertView ;
91+ }
92+
93+ private class ViewHolder {
94+ TextView text ;
95+ }
96+
97+ }
0 commit comments