Example usage for android.widget NumberPicker setMaxValue

List of usage examples for android.widget NumberPicker setMaxValue

Introduction

In this page you can find the example usage for android.widget NumberPicker setMaxValue.

Prototype

public void setMaxValue(int maxValue) 

Source Link

Document

Sets the max value of the picker.

Usage

From source file:com.matthewmitchell.wakeifyplus.NumberPickerFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final NumberPicker np = new NumberPicker(activity);
    np.setMaxValue(60);
    np.setMinValue(1);/*from  w  w w .  jav a2  s. c o  m*/
    np.setValue(defaultNum);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage("Set Snooze Minutes").setView(np)
            .setPositiveButton("Set", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.snoozeMinutes = np.getValue();
                    TextView edit = (TextView) activity.findViewById(R.id.snooze_edit);
                    edit.setText("" + activity.snoozeMinutes);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();

}

From source file:org.odk.collect.android.fragments.dialogs.NumberPickerDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.number_picker_dialog, null);

    final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.number_picker);
    numberPicker.setMaxValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1);
    numberPicker.setMinValue(0);//from  ww w  . ja v a  2s . c  o  m
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setDisplayedValues((String[]) getArguments().getSerializable(DISPLAYED_VALUES));
    numberPicker.setValue(((String[]) getArguments().getSerializable(DISPLAYED_VALUES)).length - 1
            - getArguments().getInt(PROGRESS));

    return new AlertDialog.Builder(getActivity()).setTitle("Number Picker").setView(view)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    listener.onNumberPickerValueSelected(getArguments().getInt(WIDGET_ID),
                            numberPicker.getValue());
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            }).create();
}

From source file:com.matthewmitchell.wakeifyplus.MinutesSecondsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    TableRow.LayoutParams twoLP = new TableRow.LayoutParams(0, 0, 0.2f);
    TableRow.LayoutParams threeLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, 0.3f);

    View spacer = new View(activity);
    spacer.setLayoutParams(twoLP);/*from  ww w . j a  va 2  s  .co m*/
    spacer.setVisibility(View.INVISIBLE);

    final NumberPicker minutes = new NumberPicker(activity);
    minutes.setMaxValue(30);
    minutes.setMinValue(0);
    minutes.setValue(defaultMinute);
    minutes.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout minutesLayout = new LinearLayout(activity);
    minutesLayout.addView(minutes);
    minutesLayout.setGravity(Gravity.CENTER);
    minutesLayout.setLayoutParams(threeLP);

    final NumberPicker seconds = new NumberPicker(activity);
    seconds.setMaxValue(59);
    seconds.setMinValue(0);
    seconds.setValue(defaultSecond);
    seconds.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout secondsLayout = new LinearLayout(activity);
    secondsLayout.addView(seconds);
    secondsLayout.setGravity(Gravity.CENTER);
    secondsLayout.setLayoutParams(threeLP);

    LinearLayout layout = new LinearLayout(activity);
    layout.addView(spacer);
    layout.addView(minutesLayout);
    layout.addView(secondsLayout);
    layout.setWeightSum(1.0f);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage("Set Volume Ramping Time").setView(layout)
            .setPositiveButton("Set", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.rampingMinutes = minutes.getValue();
                    activity.rampingSeconds = seconds.getValue();
                    TextView edit = (TextView) activity.findViewById(R.id.volume_ramping);
                    edit.setText(activity.rampingMinutes + "m" + activity.rampingSeconds + "s");
                }

            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();

}

From source file:com.lambdasoup.quickfit.ui.CaloriesDialogFragment.java

@NonNull
@Override/*from w w  w. ja v a 2s.  c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogContent = LayoutInflater.from(getContext()).inflate(R.layout.dialog_calories, null);
    NumberPicker numberPicker = ((NumberPicker) dialogContent.findViewById(R.id.calories_picker));
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(9999);
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setValue(getArguments().getInt(KEY_OLD_VALUE));

    return new AlertDialog.Builder(getContext()).setView(dialogContent).setTitle(R.string.title_calories)
            .setPositiveButton(R.string.button_done_calories, this).setNegativeButton(R.string.cancel, this)
            .create();
}

From source file:com.lambdasoup.quickfit.ui.DurationMinutesDialogFragment.java

@NonNull
@Override//w  w  w. j  av  a  2 s.c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogContent = LayoutInflater.from(getContext()).inflate(R.layout.dialog_duration_minutes, null);
    NumberPicker numberPicker = ((NumberPicker) dialogContent.findViewById(R.id.duration_mins_picker));
    numberPicker.setMinValue(1);
    numberPicker.setMaxValue(9999);
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setValue(getArguments().getInt(KEY_OLD_VALUE));

    return new AlertDialog.Builder(getContext()).setView(dialogContent)
            .setTitle(R.string.title_workout_duration)
            .setPositiveButton(R.string.button_done_workout_duration, this)
            .setNegativeButton(R.string.cancel, this).create();
}

From source file:org.tomasdavid.vehicleroutingproblem.fragments.MainFragment.java

/**
 * {@inheritDoc}/*w  ww. j  ava 2 s.  c  o m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);

    // time limit number picker initialization
    NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.timeLimitPicker);
    numberPicker.setMinValue(MIN_TIME_LIMIT);
    numberPicker.setMaxValue(MAX_TIME_LIMIT);
    numberPicker.setValue(DEFAULT_TIME_LIMIT);
    numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    // welcome text
    TextView welcomeText = (TextView) view.findViewById(R.id.welcome_text);
    welcomeText.setText(Html.fromHtml(getString(R.string.welcome_text)));

    // spinner for choosing algorithm initialization
    Spinner algSpinner = (Spinner) view.findViewById(R.id.algorithm_spinner);
    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.algorithms, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    algSpinner.setAdapter(spinnerAdapter);

    setHasOptionsMenu(true);
    return view;
}

From source file:ca.mudar.parkcatcher.ui.fragments.NumberPickerFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ((ParkingApp) getActivity().getApplicationContext()).updateUiLanguage();

    LayoutInflater factory = LayoutInflater.from(getActivity());
    final View view = factory.inflate(R.layout.fragment_number_picker, null);
    final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.number_picker_duration);

    numberPicker.setMinValue(Const.DURATION_MIN);
    numberPicker.setMaxValue(Const.DURATION_MAX);
    numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    int currentDuration = mListener.getParkingDuration();
    numberPicker.setValue(currentDuration);

    return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.dialog_title_duration))
            .setView(view).setPositiveButton(R.string.dialog_done, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    onDurationSet(numberPicker);
                }//from  w ww .ja va2s .  co m
            }).create();
}

From source file:com.villetainio.travelcardreminder.fragments.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
    final View view = inflater.inflate(R.layout.settings_fragment, container, false);

    // Enable notifications is true by default
    CheckBox enableNotificationsView = (CheckBox) view.findViewById(R.id.enable_notifications);
    boolean enableNotifications = cardStorage.getBoolean(getString(R.string.settings_enable_notifications),
            true);/*from  w ww . ja  v a 2 s . com*/
    enableNotificationsView.setChecked(enableNotifications);

    // Day to start notifications is 3 days before by default.
    int days = cardStorage.getInt(getString(R.string.settings_days), 3);

    // Maximum days to start notifications days left for the period
    // or 30 days if there isn't a valid period on the card.
    TravelCardReminder app = (TravelCardReminder) getActivity().getApplication();
    int daysLeft = app.calculateStatus();

    NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.days_pick);
    numberPicker.setMinValue(0);

    if (daysLeft > 0) {
        numberPicker.setMaxValue(app.calculateStatus());
    } else {
        numberPicker.setMaxValue(30);
    }
    numberPicker.setValue(days);

    // Time to start notifications is 12.00 by default.
    int hours = cardStorage.getInt(getString(R.string.settings_hours), 12);
    int minutes = cardStorage.getInt(getString(R.string.settings_minutes), 0);
    TimePicker timePicker = (TimePicker) view.findViewById(R.id.time_pick);
    timePicker.setCurrentHour(hours);
    timePicker.setCurrentMinute(minutes);

    // Save settings.
    Button saveButton = (Button) view.findViewById(R.id.save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            saveValues(view);
            Toast.makeText(getActivity().getApplicationContext(), R.string.success_message_save_settings,
                    Toast.LENGTH_LONG).show();
        }
    });

    return view;
}

From source file:com.crcrch.chromatictuner.app.NotePickerFragment.java

@NonNull
@Override//from w  w  w . ja v  a 2 s. c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());

    View dialogContent = LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.fragment_note_picker,
            null);

    final NumberPicker notePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_note);
    notePicker.setMinValue(0);
    notePicker.setMaxValue(MiscMusic.CHROMATIC_SCALE.length - 1);
    notePicker.setDisplayedValues(MiscMusic.CHROMATIC_SCALE);
    notePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    final NumberPicker octavePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_octave);
    octavePicker.setMinValue(0);
    octavePicker.setMaxValue(MAX_OCTAVE);
    octavePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    octavePicker.setWrapSelectorWheel(false);

    final TextView frequencyView = (TextView) dialogContent.findViewById(R.id.frequency);
    notePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(newVal, octavePicker.getValue()));
        }
    });
    octavePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            frequencyView.setText(selectFrequency(notePicker.getValue(), newVal));
        }
    });

    double frequencyToDisplay;
    if (savedInstanceState == null) {
        frequencyToDisplay = initialFrequency;
    } else {
        frequencyToDisplay = savedInstanceState.getDouble(STATE_FREQUENCY);
    }
    frequencyView.setText(selectFrequency(frequencyToDisplay));
    int note = getNoteForFrequency(frequencyToDisplay);
    octavePicker.setValue(getOctaveForNote(note));
    octavePicker.invalidate();
    notePicker.setValue(getNoteIndexForNote(note));
    notePicker.invalidate();

    return dialogBuilder.setTitle(R.string.dialog_title_note_picker).setView(dialogContent)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    listener.onFrequencySelected(frequency);
                    dialog.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, null).create();
}

From source file:com.yacorso.nowaste.views.adapters.FridgeFoodAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    final FridgeViewHolder holder = (FridgeViewHolder) viewHolder;

    final Food food = foodList.get(position);

    final int quantity = food.getFoodFridge().getQuantity();

    holder.tvName.setText(food.getName());
    holder.btnQuantity.setText(Integer.toString(quantity));
    Date outOfDate = food.getFoodFridge().getOutOfDate();
    holder.outOfDate.setText(getDateTextFromDate(outOfDate));
    setOpenIcon(holder.btnOpenToggle, food);

    setColorCircleFromDate(holder.btnQuantity, outOfDate, mContext.getResources());

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override/*w w  w  .  j a  va  2s.c  o m*/
        public void onClick(View v) {

            lastFoodClickedPosition = position;
            switch (v.getId()) {
            case R.id.btn_food_quantity:
                /*
                 *  Popup changement quantit
                 */
                final NumberPicker numberPicker = new NumberPicker(mContext);
                numberPicker.setMinValue(1);
                numberPicker.setMaxValue(100);
                numberPicker.setValue(quantity);
                numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

                AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                builder.setMessage(R.string.title_quantity_number_picker);
                builder.setView(numberPicker);

                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        /*
                         * Save the modification
                         */
                        int selectedValue = numberPicker.getValue();
                        food.getFoodFridge().setQuantity(selectedValue);
                        mFoodProvider.update(food);
                    }
                });

                builder.setNegativeButton(android.R.string.cancel, null);

                builder.create().show();
                break;

            case R.id.btn_open_toggle:
                /*
                 *  Open/close food
                 */
                FoodFridge foodFridge = food.getFoodFridge();
                foodFridge.toggleOpen();
                setOpenIcon(v, food);
                Date outOfDate = foodFridge.getOutOfDate();
                setColorCircleFromDate(holder.btnQuantity, outOfDate, v.getResources());
                mFoodProvider.update(food);
                break;

            case R.id.item_text_zone:
                EventBus.getDefault().post(new CallUpdateFoodEvent(food));
                break;
            case R.id.btn_favorite_toggle:
                EventBus.getDefault().post(new CallAddFoodToCustomListEvent(food));
                break;
            }
        }
    };

    holder.btnQuantity.setOnClickListener(clickListener);
    holder.btnOpenToggle.setOnClickListener(clickListener);
    holder.btnFavoriteToggle.setOnClickListener(clickListener);
    holder.textZone.setOnClickListener(clickListener);
}