Example usage for android.widget SeekBar setMax

List of usage examples for android.widget SeekBar setMax

Introduction

In this page you can find the example usage for android.widget SeekBar setMax.

Prototype

@Override
    public synchronized void setMax(int max) 

Source Link

Usage

From source file:com.andryr.musicplayer.activities.EqualizerActivity.java

private void initSeekBars() {
    ViewGroup layout = (ViewGroup) findViewById(R.id.equalizer_layout);

    final short[] range = AudioEffects.getBandLevelRange();

    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 0, 1);
    short bands = AudioEffects.getNumberOfBands();

    for (short band = 0; band < bands; band++) {

        View v = getLayoutInflater().inflate(R.layout.equalizer_slider, layout, false);

        SeekBar seekBar = (SeekBar) v.findViewById(R.id.seek_bar);

        seekBar.setMax(range[1] - range[0]);

        seekBar.setTag(band);//  w w  w.  j  a  va2  s.  c  o m

        final TextView levelTextView = (TextView) v.findViewById(R.id.level);
        seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                if (fromUser) {
                    short band = (Short) seekBar.getTag();
                    short level = (short) (seekBar.getProgress() + range[0]);
                    AudioEffects.setBandLevel(band, level);
                    levelTextView.setText((level > 0 ? "+" : "") + level / 100 + "dB");
                    mSpinner.setSelection(0);
                }

            }
        });

        layout.addView(v, band, lp);

    }

}

From source file:net.sourceforge.servestream.utils.SleepTimerDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int MAX_SLEEP_TIMER_MINUTES = 120;
    LayoutInflater factory = LayoutInflater.from(getActivity());
    final View sleepTimerView = factory.inflate(R.layout.alert_dialog_sleep_timer, null);
    final TextView sleepTimerText = (TextView) sleepTimerView.findViewById(R.id.sleep_timer_text);

    final SeekBar seekbar = (SeekBar) sleepTimerView.findViewById(R.id.seekbar);
    sleepTimerText.setText(makeTimeString(mSleepTimerMode));
    seekbar.setProgress(mSleepTimerMode);
    seekbar.setMax(MAX_SLEEP_TIMER_MINUTES);
    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override// w  ww.j a  v a 2  s .c om
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            sleepTimerText.setText(makeTimeString(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

    });

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.sleep_timer_label);
    builder.setCancelable(true);
    builder.setView(sleepTimerView);
    builder.setOnCancelListener(this);
    builder.setPositiveButton(R.string.enable_sleeptimer_label, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            mListener.onSleepTimerSet(SleepTimerDialog.this, seekbar.getProgress());
        }
    });
    return builder.create();
}

From source file:de.uni_weimar.m18.anatomiederstadt.element.SliderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_slider, container, false);
    SeekBar sb = (SeekBar) view.findViewById(R.id.seekBar);
    // scale mMin and mMax
    mMin = (int) (mMin / mGranularity);
    mMax = (int) (mMax / mGranularity);
    sb.setMax(mMax - mMin);
    sb.setProgress((mMax - mMin) / 2);// w  w  w .  j  a  v a  2s .co  m
    final RelativeLayout balloon = (RelativeLayout) view.findViewById(R.id.indicatorBalloon);
    final Space space = (Space) view.findViewById(R.id.balloonSpace);

    final Context context = getActivity();
    final TextView balloonText = (TextView) view.findViewById(R.id.indicatorTextView);
    final float[] value = { 0.0f };
    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            p.addRule(RelativeLayout.ABOVE, seekBar.getId());
            Rect thumbRect = seekBar.getThumb().getBounds();
            value[0] = mMin + progress * mGranularity;
            String valueString = new DecimalFormat("#.##").format(value[0]);
            balloonText.setText(String.valueOf(valueString) + " " + mSuffix);
            int balloonWidth = balloonText.getWidth();
            p.setMargins(thumbRect.centerX() - balloonWidth / 2, 0, 0, 0);
            balloon.setLayoutParams(p);
            balloon.setVisibility(View.VISIBLE);

            final Animation animFadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out);
            balloon.startAnimation(animFadeOut);
            animFadeOut.setStartOffset(1000);
            animFadeOut.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    balloon.setVisibility(View.INVISIBLE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            LevelStateManager stateManager = ((AnatomieDerStadtApplication) getActivity()
                    .getApplicationContext()).getStateManager(getActivity());
            stateManager.saveFloat(mVar, value[0]);
        }
    });
    return view;
}

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());/*from w  ww  .ja v  a2 s. c o m*/
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:com.precisionag.waterplane.MainActivity.java

private void configSeekbar(final Field field, final GroundOverlay overlay) {
    SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setMax(255);
    seekBar.setProgress(seekBar.getMax() / 2);
    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override//from ww  w  . java2  s .  c o m
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            updateColors(field);
            updateMarkers();
        }
    });
}

From source file:org.ounl.lifelonglearninghub.fcube.navigate.VisualSectionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_display_visual, container, false);

    ///*from   ww  w  . j  a v  a2  s  .com*/
    // Init seekbars
    //
    final TextView tvColorSample = (TextView) rootView.findViewById(R.id.tvColorSample);

    SeekBar sbRed = (SeekBar) rootView.findViewById(R.id.seekBarRed);
    sbRed.setMax(255);
    final TextView tvRValue = (TextView) rootView.findViewById(R.id.textViewRedValue);

    SeekBar sbG = (SeekBar) rootView.findViewById(R.id.seekBarGreen);
    sbG.setMax(255);
    final TextView tvGValue = (TextView) rootView.findViewById(R.id.textViewGreenValue);

    SeekBar sbB = (SeekBar) rootView.findViewById(R.id.seekBarBlue);
    sbB.setMax(255);
    final TextView tvBValue = (TextView) rootView.findViewById(R.id.textViewBlueValue);

    sbRed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            tvRValue.setText(String.valueOf(progress));

            String sR = (String) tvRValue.getText();
            Integer IsR = new Integer(sR);

            String sG = (String) tvGValue.getText();
            Integer IsG = new Integer(sG);

            String sB = (String) tvBValue.getText();
            Integer IsB = new Integer(sB);

            String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB);

            tvColorSample.setBackgroundColor(Color.parseColor(hex));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
    });

    sbG.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            tvGValue.setText(String.valueOf(progress));

            String sR = (String) tvRValue.getText();
            Integer IsR = new Integer(sR);

            String sG = (String) tvGValue.getText();
            Integer IsG = new Integer(sG);

            String sB = (String) tvBValue.getText();
            Integer IsB = new Integer(sB);

            String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB);

            tvColorSample.setBackgroundColor(Color.parseColor(hex));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
    });

    sbB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            tvBValue.setText(String.valueOf(progress));

            String sR = (String) tvRValue.getText();
            Integer IsR = new Integer(sR);

            String sG = (String) tvGValue.getText();
            Integer IsG = new Integer(sG);

            String sB = (String) tvBValue.getText();
            Integer IsB = new Integer(sB);

            String hex = String.format("#%02x%02x%02x", IsR, IsG, IsB);

            tvColorSample.setBackgroundColor(Color.parseColor(hex));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
    });

    //
    // Init number pickers
    // 
    final RadioButton rbF = (RadioButton) rootView.findViewById(R.id.rbFullColor);
    final RadioButton rbP = (RadioButton) rootView.findViewById(R.id.rbPartColor);

    npLedStart = (NumberPicker) rootView.findViewById(R.id.npLedStart);
    npLedStart.setMaxValue(15);
    npLedStart.setMinValue(0);
    npLedStart.setValue(0);
    //npLedStart.setWrapSelectorWheel(false);
    npLedStart.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int i, int i2) {
            rbP.setChecked(true);
            rbF.setChecked(false);

        }
    });

    npLedEnd = (NumberPicker) rootView.findViewById(R.id.npLedStop);
    npLedEnd.setMaxValue(15);
    npLedEnd.setMinValue(0);
    npLedEnd.setValue(15);
    //npLedEnd.setWrapSelectorWheel(false);
    npLedEnd.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int i, int i2) {
            rbP.setChecked(true);
            rbF.setChecked(false);
        }
    });

    return rootView;
}

From source file:com.precisionag.waterplane.MainActivity.java

public void updateColors(Field field) {
    //get level from seekbar
    SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setMax(255);
    int waterLevel = seekBar.getProgress();

    //update text block
    waterLevelMeters = field.minElevation
            + ((double) waterLevel * (field.maxElevation - field.minElevation) / 255.0);
    TextView waterElevationTextView = (TextView) findViewById(R.id.text);
    String elevation = new DecimalFormat("#.#").format(waterLevelMeters);
    String waterElevationText = "Elevation: " + elevation + "m";
    waterElevationTextView.setText(waterElevationText);

    int width = field.elevationBitmap.getWidth();
    int height = field.elevationBitmap.getHeight();
    int[] pixels = new int[width * height];
    field.elevationBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    Bitmap bitmap = field.elevationBitmap.copy(field.elevationBitmap.getConfig(), true);

    //test each pixel, if below water level set blue, else set transparent
    for (int i = 0; i < (width * height); i++) {
        if ((pixels[i] & 0x000000FF) < waterLevel) {
            //water is visible, set pixel to blue
            pixels[i] = 0xFF0000FF;//from   w  ww  . j  a va  2  s. com
        } else {
            //no water, set pixel transparent
            pixels[i] = 0x00000000;
        }
    }
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

    //remove old map overlay and create new one
    prevoverlay.remove();

    prevoverlay = createOverlay(bitmap, field.fieldBounds);

}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNotePagesDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    getDialog().setTitle(R.string.editor_pages_move);
    getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON);

    ViewGroup v = (ViewGroup) inflater.inflate(R.layout.snote_pages, container, false);

    int width = (int) Math.round(UIUtils.getScreenDimension(getActivity())[0] * (Float.parseFloat(
            getResources().getString(android.R.dimen.dialog_min_width_major).replace("%", "")) * 0.01));
    v.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT));

    final SeekBar seekbar = ((SeekBar) v.findViewById(R.id.seekbar_pages));
    final TextView tv = ((TextView) v.findViewById(R.id.pages_number));
    tv.setText(String.valueOf(originPageNumber + 1) + " / " + String.valueOf(totalPages));

    seekbar.setMax(totalPages - 1);
    seekbar.setProgress(originPageNumber);
    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override/*ww w . j ava2  s.c  o m*/
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            currentPageNumber = progress + 1;
            tv.setText(String.valueOf(currentPageNumber) + " / " + String.valueOf(totalPages));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    final Button validate = (Button) v.findViewById(R.id.create_document);
    final Button cancel = (Button) v.findViewById(R.id.cancel);

    validate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ((SNoteEditorActivity) getActivity()).movePage(currentPageNumber - 1);
            dismiss();
        }
    });

    cancel.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            SNotePagesDialogFragment.this.dismiss();
        }
    });

    return v;
}

From source file:com.esri.arcgisruntime.sample.blendrenderer.ParametersDialogFragment.java

/**
 * Builds parameter dialog with values pulled through from MainActivity.
 *
 * @param savedInstanceState//from www  .java2s .  co m
 * @return create parameter dialog box
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Bundle blendParameters = getArguments();
    if (blendParameters != null) {
        mAltitude = blendParameters.getInt("altitude");
        mAzimuth = blendParameters.getInt("azimuth");
        mSlopeType = (SlopeType) blendParameters.getSerializable("slope_type");
        mColorRampType = (ColorRamp.PresetType) blendParameters.getSerializable("color_ramp_type");
    }

    final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext());
    @SuppressLint("InflateParams")
    View dialogView = inflater.inflate(R.layout.dialog_box, null);
    paramDialog.setView(dialogView);
    paramDialog.setTitle(R.string.dialog_title);
    paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            ParametersListener activity = (ParametersListener) getActivity();
            activity.returnParameters(mAltitude, mAzimuth, mSlopeType, mColorRampType);
        }
    });

    mCurrAltitudeTextView = (TextView) dialogView.findViewById(R.id.curr_altitude_text);
    SeekBar altitudeSeekBar = (SeekBar) dialogView.findViewById(R.id.altitude_seek_bar);
    altitudeSeekBar.setMax(90); //altitude is restricted to 0 - 90
    //set initial altitude value
    updateAltitudeSeekBar(altitudeSeekBar);
    altitudeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAltitude = progress;
            updateAltitudeSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mCurrAzimuthTextView = (TextView) dialogView.findViewById(R.id.curr_azimuth_text);
    SeekBar azimuthSeekBar = (SeekBar) dialogView.findViewById(R.id.azimuth_seek_bar);
    azimuthSeekBar.setMax(360); //azimuth measured in degrees 0 - 360
    //set initial azimuth value
    updateAzimuthSeekBar(azimuthSeekBar);
    azimuthSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAzimuth = progress;
            updateAzimuthSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    List<String> slopeTypeArray = new ArrayList<>();
    slopeTypeArray.add("None"); //ordinals:0
    slopeTypeArray.add("Degree"); //1
    slopeTypeArray.add("Percent rise"); //2
    slopeTypeArray.add("Scaled"); //3

    ArrayAdapter<String> slopeTypeSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            slopeTypeArray);

    Spinner slopeTypeSpinner = (Spinner) dialogView.findViewById(R.id.slope_type_spinner);
    slopeTypeSpinner.setAdapter(slopeTypeSpinnerAdapter);
    slopeTypeSpinner.setSelection(mSlopeType.ordinal());
    slopeTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mSlopeType = SlopeType.NONE;
                break;
            case 1:
                mSlopeType = SlopeType.DEGREE;
                break;
            case 2:
                mSlopeType = SlopeType.PERCENT_RISE;
                break;
            case 3:
                mSlopeType = SlopeType.SCALED;
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    List<String> colorRampTypeArray = new ArrayList<>();
    colorRampTypeArray.add("None"); //ordinals:0
    colorRampTypeArray.add("Elevation"); //1
    colorRampTypeArray.add("DEM screen"); //2
    colorRampTypeArray.add("DEM light"); //3

    ArrayAdapter<String> colorRampSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            colorRampTypeArray);

    Spinner colorRampSpinner = (Spinner) dialogView.findViewById(R.id.color_ramp_spinner);
    colorRampSpinner.setAdapter(colorRampSpinnerAdapter);
    colorRampSpinner.setSelection(mColorRampType.ordinal());
    colorRampSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mColorRampType = ColorRamp.PresetType.NONE;
                break;
            case 1:
                mColorRampType = ColorRamp.PresetType.ELEVATION;
                break;
            case 2:
                mColorRampType = ColorRamp.PresetType.DEM_SCREEN;
                break;
            case 3:
                mColorRampType = ColorRamp.PresetType.DEM_LIGHT;
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    return paramDialog.create();
}

From source file:layout.BeaconTabFragment.java

/**
 * Setting up the advertising interval component with a seek bar which can be set to values from
 * 100 to 1024. There is also a tracking TextView which shows the numeric representation of the
 * advertising interval./*from   ww w .  j  ava2 s  .  c  o m*/
 *
 * @param v container for the advertising interval component. This is usually the main container
 *          in the tab. It has to be added to the activity before calling this method.
 */
private void setUpAdvertisingInterval(View v) {
    if (advInterval != null) {

        v.findViewById(R.id.adv_int_info).setVisibility(View.VISIBLE);
        final TextView advIntervalView = (TextView) v.findViewById(R.id.adv_interval);
        advIntervalView.setText(advInterval);
        SeekBar advInterSeekBar = (SeekBar) v.findViewById(R.id.adv_interval_seek_bar);
        advInterSeekBar.setMax(1024 - 100);
        int progress = Integer.parseInt(advInterval) - 100;
        advInterSeekBar.setProgress(progress);
        advInterSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                int progress = seekBar.getProgress() + 100;
                advIntervalView.setText(Integer.toString(progress));
                advIntervalChanged = true;
                advInterval = advIntervalView.getText().toString();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }
}