22
33import android .app .Activity ;
44import android .support .annotation .NonNull ;
5+ import android .text .TextUtils ;
56import android .view .Gravity ;
67import android .view .View ;
78import android .widget .LinearLayout ;
9+ import android .widget .TextView ;
810
911import java .util .ArrayList ;
1012import java .util .List ;
@@ -25,6 +27,8 @@ public class DoublePicker extends WheelPicker {
2527 private int selectedSecondIndex = 0 ;
2628 private OnWheelListener onWheelListener ;
2729 private OnPickListener onPickListener ;
30+ private CharSequence firstPrefixLabel , firstSuffixLabel ;
31+ private CharSequence secondPrefixLabel , secondSuffixLabel ;
2832
2933 public DoublePicker (Activity activity , List <String > firstData , List <String > secondData ) {
3034 super (activity );
@@ -41,6 +45,16 @@ public void setSelectedIndex(int firstIndex, int secondIndex) {
4145 }
4246 }
4347
48+ public void setFirstLabel (CharSequence firstPrefixLabel , CharSequence firstSuffixLabel ) {
49+ this .firstPrefixLabel = firstPrefixLabel ;
50+ this .firstSuffixLabel = firstSuffixLabel ;
51+ }
52+
53+ public void setSecondLabel (CharSequence secondPrefixLabel , CharSequence secondSuffixLabel ) {
54+ this .secondPrefixLabel = secondPrefixLabel ;
55+ this .secondSuffixLabel = secondSuffixLabel ;
56+ }
57+
4458 public String getSelectedFirstItem () {
4559 if (firstData .size () > selectedFirstIndex ) {
4660 return firstData .get (selectedFirstIndex );
@@ -61,12 +75,36 @@ protected View makeCenterView() {
6175 LinearLayout layout = new LinearLayout (activity );
6276 layout .setOrientation (LinearLayout .HORIZONTAL );
6377 layout .setGravity (Gravity .CENTER );
78+ if (!TextUtils .isEmpty (firstPrefixLabel )) {
79+ TextView firstPrefixLabelView = createLabelView ();
80+ firstPrefixLabelView .setLayoutParams (new LinearLayout .LayoutParams (WRAP_CONTENT , WRAP_CONTENT ));
81+ firstPrefixLabelView .setText (firstPrefixLabel );
82+ layout .addView (firstPrefixLabelView );
83+ }
6484 final WheelView firstView = createWheelView ();
6585 firstView .setLayoutParams (new LinearLayout .LayoutParams (0 , WRAP_CONTENT , 1.0f ));
6686 layout .addView (firstView );
87+ if (!TextUtils .isEmpty (firstSuffixLabel )) {
88+ TextView firstSuffixLabelView = createLabelView ();
89+ firstSuffixLabelView .setLayoutParams (new LinearLayout .LayoutParams (WRAP_CONTENT , WRAP_CONTENT ));
90+ firstSuffixLabelView .setText (firstSuffixLabel );
91+ layout .addView (firstSuffixLabelView );
92+ }
93+ if (!TextUtils .isEmpty (secondPrefixLabel )) {
94+ TextView secondPrefixLabelView = createLabelView ();
95+ secondPrefixLabelView .setLayoutParams (new LinearLayout .LayoutParams (WRAP_CONTENT , WRAP_CONTENT ));
96+ secondPrefixLabelView .setText (secondPrefixLabel );
97+ layout .addView (secondPrefixLabelView );
98+ }
6799 final WheelView secondView = createWheelView ();
68100 secondView .setLayoutParams (new LinearLayout .LayoutParams (0 , WRAP_CONTENT , 1.0f ));
69101 layout .addView (secondView );
102+ if (!TextUtils .isEmpty (secondSuffixLabel )) {
103+ TextView secondSuffixLabelView = createLabelView ();
104+ secondSuffixLabelView .setLayoutParams (new LinearLayout .LayoutParams (WRAP_CONTENT , WRAP_CONTENT ));
105+ secondSuffixLabelView .setText (secondSuffixLabel );
106+ layout .addView (secondSuffixLabelView );
107+ }
70108 firstView .setItems (firstData , selectedFirstIndex );
71109 firstView .setOnItemSelectListener (new WheelView .OnItemSelectListener () {
72110 @ Override
0 commit comments