本文整理汇总了Java中android.widget.NumberPicker.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Java NumberPicker.setFormatter方法的具体用法?Java NumberPicker.setFormatter怎么用?Java NumberPicker.setFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.NumberPicker
的用法示例。
在下文中一共展示了NumberPicker.setFormatter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initNumPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* 初始化传入的moneyPicker
*
* @param numberPickerArrayList 需要初始化的NumPicker
*/
private void initNumPicker(ArrayList<NumberPicker> numberPickerArrayList) {
Iterator iterator = numberPickerArrayList.iterator();
while (iterator.hasNext()) {
NumberPicker moneyPicker = (NumberPicker) iterator.next();
moneyPicker.setFormatter(this);
moneyPicker.setOnValueChangedListener(this);
moneyPicker.setOnScrollListener(this);
moneyPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
}
numberPickerArrayList.get(0).setMinValue(3);numberPickerArrayList.get(0).setMaxValue(15);//早餐的价格区间
numberPickerArrayList.get(1).setMinValue(5);numberPickerArrayList.get(1).setMaxValue(30);//午餐的价格区间
numberPickerArrayList.get(2).setMinValue(5);numberPickerArrayList.get(2).setMaxValue(30);//晚餐的价格区间
numberPickerArrayList.get(0).setValue(preferences.getInt("moneyBreakfastChosen", 5));//早餐默认为5
numberPickerArrayList.get(1).setValue(preferences.getInt("moneyLunchChosen", 10));//午饭默认为10
numberPickerArrayList.get(2).setValue(preferences.getInt("moneyDinnerChosen", 12));//早餐默认为12
}
示例2: setupSecondPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* Set the reference of seconds picker, its digit format and register value change listener.
*
* @param pickerVisible if false, removes the spinner widget.
*/
@TargetApi(11)
protected void setupSecondPicker(boolean pickerVisible) {
mSecondPicker = (NumberPicker) findViewById(R.id.seconds);
if (pickerVisible) {
mSecondPicker.setMinValue(0);
mSecondPicker.setMaxValue(59);
mSecondPicker.setFormatter(TWO_DIGIT_FORMATTER);
mSecondPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mCurrentSecond = newVal;
}
});
} else {
mHourPicker.setVisibility(View.GONE);
}
}
示例3: setupMinutePicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* Set the reference of minute picker, its digit format and register value change listener.
*
* @param pickerVisible if false, removes the spinner widget.
*/
@TargetApi(11)
protected void setupMinutePicker(boolean pickerVisible) {
mMinutePicker = (NumberPicker) findViewById(R.id.minute);
if (pickerVisible) {
mMinutePicker.setMinValue(0);
mMinutePicker.setMaxValue(59);
mMinutePicker.setFormatter(TWO_DIGIT_FORMATTER);
mMinutePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker spinner, int oldVal, int newVal) {
mCurrentMinute = newVal;
}
});
} else {
mMinutePicker.setVisibility(View.GONE);
findViewById(R.id.minute_divider).setVisibility(View.GONE);
}
}
示例4: setupHourPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* Set the reference of hour picker, its digit format and register value change listener.
*
* @param pickerVisible if false, removes the spinner widget.
*/
@TargetApi(11)
protected void setupHourPicker(boolean pickerVisible) {
mHourPicker = (NumberPicker) findViewById(R.id.hour);
if (pickerVisible) {
mHourPicker.setMinValue(0);
mHourPicker.setMaxValue(10);
mHourPicker.setFormatter(TWO_DIGIT_FORMATTER);
mHourPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mCurrentHour = newVal;
}
});
} else {
mHourPicker.setVisibility(View.GONE);
findViewById(R.id.hour_divider).setVisibility(View.GONE);
}
}
示例5: TimeLimitationPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
public TimeLimitationPicker(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.item_time_limitation_picker, this);
title = (TextView) findViewById(R.id.title);
startHourPicker = (NumberPicker) findViewById(R.id.start_hour_picker);
startMinutePicker = (NumberPicker) findViewById(R.id.start_minute_picker);
endHourPicker = (NumberPicker) findViewById(R.id.end_hour_picker);
endMinutePicker = (NumberPicker) findViewById(R.id.end_minute_picker);
NumberPicker.Formatter formatter = new NumberPicker.Formatter() {
@Override
public String format(int value) {
return String.format("%02d", value);
}
};
startHourPicker.setMaxValue(23);
startHourPicker.setMinValue(0);
startHourPicker.setValue(7);
startHourPicker.setFormatter(formatter);
startHourPicker.setWrapSelectorWheel(true);
startMinutePicker.setMaxValue(59);
startMinutePicker.setMinValue(0);
startMinutePicker.setValue(0);
startMinutePicker.setFormatter(formatter);
startMinutePicker.setWrapSelectorWheel(true);
endHourPicker.setMaxValue(23);
endHourPicker.setMinValue(0);
endHourPicker.setValue(7);
endHourPicker.setFormatter(formatter);
endHourPicker.setWrapSelectorWheel(true);
endMinutePicker.setMaxValue(59);
endMinutePicker.setMinValue(0);
endMinutePicker.setValue(0);
endMinutePicker.setFormatter(formatter);
endMinutePicker.setWrapSelectorWheel(true);
}
示例6: prepareNumberPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* Customizes the options shown in the {@link NumberPicker}s to represent i with the string
* i - 1 and 0 with a blank option
*
* @param id
*/
private void prepareNumberPicker(int id) {
NumberPicker np = (NumberPicker) findViewById(id);
np.setMinValue(0);
np.setMaxValue(1001);
np.setWrapSelectorWheel(false);
np.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int i) {
if (i == 0) return " ";
return String.valueOf(i - 1);
}
});
}
示例7: prepareCaffeineNumberPicker
import android.widget.NumberPicker; //导入方法依赖的package包/类
/**
* Customizes the options shown in the {@link NumberPicker}s to represent i with the string
* (i - 1) * 10 and 0 with a blank option. That means that the step for the caffeine is 10
* instead of 1
*
* @param id
*/
private void prepareCaffeineNumberPicker(int id) {
NumberPicker np = (NumberPicker) findViewById(id);
np.setMinValue(0);
np.setMaxValue(10010);
np.setWrapSelectorWheel(false);
np.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int i) {
if (i == 0) return " ";
return String.valueOf((i - 1) * 10);
}
});
}
示例8: onBindDialogView
import android.widget.NumberPicker; //导入方法依赖的package包/类
@Override
protected void onBindDialogView(View view) {
String[] values = mCurrentTime.split(":");
int hours = Integer.valueOf(values[0]);
int minutes = Integer.valueOf(values[1]);
int seconds = Integer.valueOf(values[2]);
mHourPicker = (NumberPicker) view.findViewById(R.id.hour);
mHourPicker.setMinValue(0);
mHourPicker.setMaxValue(10);
mHourPicker.setFormatter(TWO_DIGITS_FORMATTER);
mHourPicker.setValue(hours);
mHourPicker.setOnValueChangedListener(this); // min time is 5s
mMinutePicker = (NumberPicker) view.findViewById(R.id.minute);
mMinutePicker.setMinValue(0);
mMinutePicker.setMaxValue(59);
mMinutePicker.setFormatter(TWO_DIGITS_FORMATTER);
mMinutePicker.setValue(minutes);
mMinutePicker.setOnValueChangedListener(this); // min time is 5s
mSecondPicker = (NumberPicker) view.findViewById(R.id.seconds);
mSecondPicker.setMinValue(0); // see onValueChange method
mSecondPicker.setMaxValue(59);
mSecondPicker.setFormatter(TWO_DIGITS_FORMATTER);
mSecondPicker.setValue(seconds);
mSecondPicker.setOnValueChangedListener(this); // min time is 5s
super.onBindDialogView(view);
}
示例9: onCreateView
import android.widget.NumberPicker; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_time_limited_periodic_care, container, false);
goalPicker = (NumberPicker) view.findViewById(R.id.goal_picker);
punishmentPicker = (NumberPicker) view.findViewById(R.id.punishment_picker);
lengthPicker = (NumberPicker) view.findViewById(R.id.length_picker);
unitPicker = (NumberPicker) view.findViewById(R.id.unit_picker);
startHourPicker = (NumberPicker) view.findViewById(R.id.start_hour_picker);
startMinutePicker = (NumberPicker) view.findViewById(R.id.start_minute_picker);
endHourPicker = (NumberPicker) view.findViewById(R.id.end_hour_picker);
endMinutePicker = (NumberPicker) view.findViewById(R.id.end_minute_picker);
goalPicker.setMaxValue(Integer.MAX_VALUE);
goalPicker.setMinValue(1);
goalPicker.setWrapSelectorWheel(false);
punishmentPicker.setMaxValue(Integer.MAX_VALUE);
punishmentPicker.setMinValue(0);
punishmentPicker.setValue(1);
punishmentPicker.setWrapSelectorWheel(false);
lengthPicker.setMaxValue(Integer.MAX_VALUE);
lengthPicker.setMinValue(1);
lengthPicker.setWrapSelectorWheel(false);
unitPicker.setDisplayedValues(getResources().getStringArray(R.array.period_units));
unitPicker.setMaxValue(3);
unitPicker.setMinValue(0);
unitPicker.setValue(3);
unitPicker.setWrapSelectorWheel(true);
NumberPicker.Formatter formatter = new NumberPicker.Formatter() {
@Override
public String format(int value) {
return String.format("%02d", value);
}
};
startHourPicker.setMaxValue(23);
startHourPicker.setMinValue(0);
startHourPicker.setValue(7);
startHourPicker.setFormatter(formatter);
startHourPicker.setWrapSelectorWheel(true);
startMinutePicker.setMaxValue(59);
startMinutePicker.setMinValue(0);
startMinutePicker.setValue(0);
startMinutePicker.setFormatter(formatter);
startMinutePicker.setWrapSelectorWheel(true);
endHourPicker.setMaxValue(23);
endHourPicker.setMinValue(0);
endHourPicker.setValue(7);
endHourPicker.setFormatter(formatter);
endHourPicker.setWrapSelectorWheel(true);
endMinutePicker.setMaxValue(59);
endMinutePicker.setMinValue(0);
endMinutePicker.setValue(0);
endMinutePicker.setFormatter(formatter);
endMinutePicker.setWrapSelectorWheel(true);
return view;
}