List of usage examples for android.widget Spinner setSelection
public void setSelection(int position, boolean animate)
From source file:com.asksven.betterbatterystats.StatsActivity.java
private void refreshSpinners() { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if ((m_refFromName == null) && (m_refToName == null)) { Toast.makeText(this, getString(R.string.info_fallback_to_default), Toast.LENGTH_SHORT).show(); m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME); m_refToName = Reference.CURRENT_REF_FILENAME; if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) { m_refFromName = Reference.BOOT_REF_FILENAME; }/* w ww. j a v a 2s. c om*/ Log.e(TAG, "refreshSpinners: reset null references: from='" + m_refFromName + "', to='" + m_refToName + "'"); } // reload the spinners to make sure all refs are in the right sequence m_spinnerFromAdapter.refreshFromSpinner(this); m_spinnerToAdapter.filterToSpinner(m_refFromName, this); // after we reloaded the spinners we need to reset the selections Spinner spinnerStatTypeFrom = (Spinner) findViewById(R.id.spinnerStatType); Spinner spinnerStatTypeTo = (Spinner) findViewById(R.id.spinnerStatSampleEnd); if (LogSettings.DEBUG) { Log.i(TAG, "refreshSpinners: reset spinner selections: from='" + m_refFromName + "', to='" + m_refToName + "'"); Log.i(TAG, "refreshSpinners Spinner values: SpinnerFrom=" + m_spinnerFromAdapter.getNames() + " SpinnerTo=" + m_spinnerToAdapter.getNames()); Log.i(TAG, "refreshSpinners: request selections: from='" + m_spinnerFromAdapter.getPosition(m_refFromName) + "', to='" + m_spinnerToAdapter.getPosition(m_refToName) + "'"); } // restore positions spinnerStatTypeFrom.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName), true); if (spinnerStatTypeTo.isShown()) { spinnerStatTypeTo.setSelection(m_spinnerToAdapter.getPosition(m_refToName), true); } else { spinnerStatTypeTo.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME), true); } if (LogSettings.DEBUG) Log.i(TAG, "refreshSpinners result positions: from='" + spinnerStatTypeFrom.getSelectedItemPosition() + "', to='" + spinnerStatTypeTo.getSelectedItemPosition() + "'"); if ((spinnerStatTypeTo.isShown()) && ((spinnerStatTypeFrom.getSelectedItemPosition() == -1) || (spinnerStatTypeTo.getSelectedItemPosition() == -1))) { Toast.makeText(StatsActivity.this, getString(R.string.info_loading_refs_error), Toast.LENGTH_LONG) .show(); } }
From source file:gr.scify.newsum.ui.ViewActivity.java
@Override public void onGesturePerformed(GestureOverlayView overlay, final Gesture gesture) { // Get the Topic IDs per Category. Null means that all User Sources are // accepted/*from www . j a va2 s. c o m*/ // User Sources is a separator delimited string containing the URL feeds final ProgressDialog pd = ProgressDialog.show(ViewActivity.this, "", getResources().getText(R.string.wait_msg)); new Thread(new Runnable() { @Override public void run() { final Spinner spinner = (Spinner) findViewById(R.id.spinner1); ArrayList<Prediction> predictions = gestureLib.recognize(gesture); for (Prediction prediction : predictions) { if (prediction.score > 1.0) { // track the swipe Action per category if (getAnalyticsPref()) { EasyTracker.getTracker().sendEvent(SWIPING_ACTION, "Normal View", Category, 0l); } if (prediction.name.contains("right")) { if (spinner.getSelectedItemPosition() > 0) { runOnUiThread(new Runnable() { public void run() { spinner.setSelection(spinner.getSelectedItemPosition() - 1, true); }; }); } } else { if (spinner.getSelectedItemPosition() < saTopicIDsLength - 1) { runOnUiThread(new Runnable() { public void run() { spinner.setSelection(spinner.getSelectedItemPosition() + 1, true); }; }); } } } } runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); } }); } }).start(); }
From source file:nf.frex.android.FrexActivity.java
private void preparePropertiesDialog(final Dialog dialog) { final Registry<Fractal> fractals = Registries.fractals; int fractalTypeIndex = fractals.getIndex(view.getFractalId()); final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner); final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar); final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text); final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box); final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box); final Button okButton = (Button) dialog.findViewById(R.id.ok_button); final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); juliaModeCheckBox.setEnabled(true);/*from w w w . ja va2 s . c o m*/ ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, fractals.getIds()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fractalTypeSpinner.setAdapter(arrayAdapter); fractalTypeSpinner.setSelection(fractalTypeIndex, true); fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { Fractal fractal = fractals.getValue(position); iterationsEditText.setText(fractal.getDefaultIterMax() + ""); boolean sameFractal = view.getFractalId().equals(fractals.getId(position)); if (!sameFractal) { juliaModeCheckBox.setChecked(false); } juliaModeCheckBox.setEnabled(sameFractal); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL); final double iterationsMin = 1; final double iterationsMax = 3; final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar, iterationsMin, iterationsMax, true, view.getIterMax()); iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { int iterMax = iterationsSeekBarConfigurer.getValueInt(); iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { try { int iterMax = Integer.parseInt(v.getText().toString()); iterationsSeekBarConfigurer.setValue(iterMax); return true; } catch (NumberFormatException e) { return false; } } }); decoratedFractal.setChecked(view.isDecoratedFractal()); juliaModeCheckBox.setChecked(view.isJuliaModeFractal()); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int iterMax; try { iterMax = Integer.parseInt(iterationsEditText.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); return; } dialog.dismiss(); String oldConfigName = view.getConfigName(); String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition()); Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition()); String oldFractalId = view.getFractalId(); boolean newJuliaModeFractal = juliaModeCheckBox.isChecked(); boolean oldJuliaModeFractal = view.isJuliaModeFractal(); view.setFractalId(newFractalId); view.setIterMax(iterMax); view.setDecoratedFractal(decoratedFractal.isChecked()); view.setJuliaModeFractal(newJuliaModeFractal); boolean fractalTypeChanged = !oldFractalId.equals(newFractalId); if (fractalTypeChanged) { if (oldConfigName.contains(oldFractalId.toLowerCase())) { view.setConfigName(newFractalId.toLowerCase()); } view.setRegion(fractal.getDefaultRegion()); view.setBailOut(fractal.getDefaultBailOut()); } boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal; if (fractalTypeChanged || juliaModeChanged) { view.getRegionHistory().clear(); view.getRegionHistory().add(fractal.getDefaultRegion().clone()); } view.recomputeAll(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }