2016-12-25 63 views
0

我試着做這樣的事情如何實現這個自定義數字選擇器?

This is what i wanna achieve
你如何實現第二個值和第三值選擇器?
我需要更改爲datepicker嗎?

*編輯

用於第二值i嘗試這種方法:

private String[] getDatesFromCalender() { 
    Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone("GMT+7")); 
    Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT+7")); 

    List<String> dates = new ArrayList<String>(); 
    DateFormat dateFormat = new SimpleDateFormat("EE, dd MMM", new Locale("en", "Singapore")); 
    dates.add(dateFormat.format(c1.getTime())); 

    for (int i = 0; i < 60; i++) { 
     c1.add(Calendar.DATE, 1); 
     dates.add(dateFormat.format(c1.getTime())); 
    } 
    c2.add(Calendar.DATE, -60); 

    for (int i = 0; i < 60; i++) { 
     c2.add(Calendar.DATE, 1); 
     dates.add(dateFormat.format(c2.getTime())); 
    } 
    return dates.toArray(new String[dates.size() - 1]); 
} 

然後把這上的onCreate

date = getDatesFromCalender(); 

並設置numberpicker

private void setUpDatePicker() { 
    npBookingDate.setDisplayedValues(date); 
    npBookingDate.setMaxValue(date.length - 1); 
    npBookingDate.setMinValue(0); 
    npBookingDate.setFormatter(new NumberPicker.Formatter() { 
     @Override 
     public String format(int value) { 
      return date[value]; 
     } 
    }); 
} 

結果是我想要什麼,但它添加另一個日期之前,今天檢查圖片:
Here is what i tried
如何禁用日期之前今天日期?

回答

0

行,用於示出在相同的對話2個選擇器,我將發佈一個代碼段如下所示

LinearLayout LL = new LinearLayout(mContext); 
LL.setOrientation(LinearLayout.HORIZONTAL); 
// 
final NumberPicker aNumberPicker = new NumberPicker(mContext); 
aNumberPicker.setMaxValue(50); 
aNumberPicker.setMinValue(1); 
// 
final NumberPicker aNumberPickerA = new NumberPicker(mContext); 
aNumberPickerA.setMaxValue(11); 
aNumberPickerA.setMinValue(1); 
aNumberPickerA.setDisplayedValues(new String[] { "Tea Cup", "Glass","Plate","Small Plate","Cutlets","Medium","Piece","Katori","Balls","Serving","egg"}); 
// 
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(50, 50); 
params.gravity = Gravity.CENTER; 
// 
LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
numPicerParams.weight = 1; 
// 
LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
qPicerParams.weight = 1; 
// 
LL.setLayoutParams(params); 
LL.addView(aNumberPicker,numPicerParams); 
LL.addView(aNumberPickerA,qPicerParams); 

所以,對於3個選擇器,則可以添加線性佈局內的一個以上數選擇器視圖並將此視圖附加到對話框片段,並且您可以實現功能

+0

我認爲我可以通過numberpicker實現良好的功能..我想實現的是如何獲得第二個和第三個值選擇器 –

+0

即使盡管感謝hasif是不是我想要的 –

相關問題