Java Code Examples for android.widget.Spinner#getSelectedItemPosition()
The following examples show how to use
android.widget.Spinner#getSelectedItemPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntervalSetting.java From revolution-irc with GNU General Public License v3.0 | 6 votes |
static int getInterval(Spinner spinner, EditText editText) { int mp = 1; switch (spinner.getSelectedItemPosition()) { case SPINNER_SECONDS: mp = 1000; // seconds break; case SPINNER_MINUTES: mp = 1000 * 60; // minutes break; case SPINNER_HOURS: mp = 1000 * 60 * 60; // hours break; } try { return (int) (Double.parseDouble(editText.getText().toString()) * mp); } catch (NumberFormatException e) { return -1; } }
Example 2
Source File: LabelPrintTraitLayout.java From Field-Book with GNU General Public License v2.0 | 6 votes |
public String getValueFromSpinner(Spinner spinner, String[] options) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); String value = ""; if (spinner.getSelectedItem().toString().equals("date")) { value = dateFormat.format(calendar.getTime()); } else if (spinner.getSelectedItem().toString().equals("trial_name")) { value = getPrefs().getString("FieldFile", ""); } else if (spinner.getSelectedItem().toString().equals("blank")) { value = ""; } else { int pos = spinner.getSelectedItemPosition(); value = ConfigActivity.dt.getDropDownRange(options[pos], getCRange().plot_id)[0]; } return value; }
Example 3
Source File: ConfigureStandupTimer.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public void onClick(View v) { Intent i = new Intent(this, StandupTimer.class); meetingLength = getMeetingLengthFromUI(); i.putExtra("meetingLength", meetingLength); TextView t = (TextView) findViewById(R.id.num_participants); numParticipants = parseNumberOfParticipants(t); i.putExtra("numParticipants", numParticipants); Spinner teamNameSpinner = (Spinner) findViewById(R.id.team_names); teamNamesPos = teamNameSpinner.getSelectedItemPosition(); i.putExtra("teamName", (String) teamNameSpinner.getSelectedItem()); if (numParticipants < 1 || (Prefs.allowUnlimitedParticipants(this) == false && numParticipants > 20)) { showInvalidNumberOfParticipantsDialog(); } else { saveState(); startTimer(i); } }
Example 4
Source File: TGBrowserView.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings("unchecked") public void refreshCollections(boolean forceDefaults) { ArrayAdapter<TGSelectableItem> arrayAdapter = new ArrayAdapter<TGSelectableItem>(findActivity(), android.R.layout.simple_spinner_item, createCollectionValues()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); TGBrowserCollection selectedCollection = (forceDefaults ? TGBrowserManager.getInstance(this.findContext()).getDefaultCollection() : this.findCurrentCollection()); TGSelectableItem selectedItem = new TGSelectableItem(selectedCollection, null); Integer selectedItemPosition = arrayAdapter.getPosition(selectedItem); Spinner spinner = (Spinner) this.findViewById(R.id.browser_collections); OnItemSelectedListener listener = spinner.getOnItemSelectedListener(); spinner.setOnItemSelectedListener(null); if(!this.isSameCollection(arrayAdapter, (ArrayAdapter<TGSelectableItem>) spinner.getAdapter())) { spinner.setAdapter(arrayAdapter); } spinner.setOnItemSelectedListener(listener); if( spinner.getSelectedItemPosition() != selectedItemPosition ) { spinner.setSelection(selectedItemPosition, false); } }
Example 5
Source File: MainActivity.java From DroneKit-Android-Starter with Apache License 2.0 | 6 votes |
public void onBtnConnectTap(View view) { if (this.drone.isConnected()) { this.drone.disconnect(); } else { Spinner connectionSelector = (Spinner) findViewById(R.id.selectConnectionType); int selectedConnectionType = connectionSelector.getSelectedItemPosition(); Bundle extraParams = new Bundle(); if (selectedConnectionType == ConnectionType.TYPE_USB) { extraParams.putInt(ConnectionType.EXTRA_USB_BAUD_RATE, DEFAULT_USB_BAUD_RATE); // Set default baud rate to 57600 } else { extraParams.putInt(ConnectionType.EXTRA_UDP_SERVER_PORT, DEFAULT_UDP_PORT); // Set default baud rate to 14550 } ConnectionParameter connectionParams = new ConnectionParameter(selectedConnectionType, extraParams, null); this.drone.connect(connectionParams); } }
Example 6
Source File: PlayMovieSurfaceActivity.java From grafika with Apache License 2.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; mSelectedMovie = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + mSelectedMovie + " '" + mMovieFiles[mSelectedMovie] + "'"); }
Example 7
Source File: CameraCaptureActivity.java From grafika with Apache License 2.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; final int filterNum = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + filterNum); mGLView.queueEvent(new Runnable() { @Override public void run() { // notify the renderer that we want to change the encoder's state mRenderer.changeFilterMode(filterNum); } }); }
Example 8
Source File: PlayMovieActivity.java From grafika with Apache License 2.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; mSelectedMovie = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + mSelectedMovie + " '" + mMovieFiles[mSelectedMovie] + "'"); }
Example 9
Source File: UserMeasurementView.java From openScale with GNU General Public License v3.0 | 5 votes |
@Override protected boolean validateAndSetInput(View view) { Spinner spinScaleUser = (Spinner)view; int pos = spinScaleUser.getSelectedItemPosition(); setValue(openScale.getScaleUserList().get(pos).getId(), true); return true; }
Example 10
Source File: CameraCaptureActivity.java From AndroidPlayground with MIT License | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; final int filterNum = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + filterNum); mGLView.queueEvent(new Runnable() { @Override public void run() { // notify the renderer that we want to change the encoder's state mRenderer.changeFilterMode(filterNum); } }); }
Example 11
Source File: CameraCaptureActivity.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; final int filterNum = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + filterNum); mGLView.queueEvent(new Runnable() { @Override public void run() { // notify the renderer that we want to change the encoder's state mRenderer.changeFilterMode(filterNum); } }); }
Example 12
Source File: PlayMovieSurfaceActivity.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; mSelectedMovie = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + mSelectedMovie + " '" + mMovieFiles[mSelectedMovie] + "'"); }
Example 13
Source File: CameraCaptureActivity.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
@Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Spinner spinner = (Spinner) parent; final int filterNum = spinner.getSelectedItemPosition(); Log.d(TAG, "onItemSelected: " + filterNum); mGLView.queueEvent(new Runnable() { @Override public void run() { // notify the renderer that we want to change the encoder's state mRenderer.changeFilterMode(filterNum); } }); }
Example 14
Source File: AddOrEditContactFragment.java From BlackList with Apache License 2.0 | 5 votes |
private int getNumberType(View row) { Spinner numberTypeSpinner = (Spinner) row.findViewById(R.id.spinner_number_type); switch (numberTypeSpinner.getSelectedItemPosition()) { case 1: return ContactNumber.TYPE_CONTAINS; case 2: return ContactNumber.TYPE_STARTS; case 3: return ContactNumber.TYPE_ENDS; } return ContactNumber.TYPE_EQUALS; }
Example 15
Source File: SampleTests.java From android-ActivityInstrumentation with Apache License 2.0 | 4 votes |
/** * Test to make sure that spinner values are persisted across activity restarts. * * <p>Launches the main activity, sets a spinner value, closes the activity, then relaunches * that activity. Checks to make sure that the spinner values match what we set them to. */ // BEGIN_INCLUDE (test_name) public void testSpinnerValuePersistedBetweenLaunches() { // END_INCLUDE (test_name) final int TEST_SPINNER_POSITION_1 = MainActivity.WEATHER_PARTLY_CLOUDY; // BEGIN_INCLUDE (launch_activity) // Launch the activity Activity activity = getActivity(); // END_INCLUDE (launch_activity) // BEGIN_INCLUDE (write_to_ui) // Set spinner to test position 1 final Spinner spinner1 = (Spinner) activity.findViewById(R.id.spinner); activity.runOnUiThread(new Runnable() { @Override public void run() { // Attempts to manipulate the UI must be performed on a UI thread. // Calling this outside runOnUiThread() will cause an exception. // // You could also use @UiThreadTest, but activity lifecycle methods // cannot be called if this annotation is used. spinner1.requestFocus(); spinner1.setSelection(TEST_SPINNER_POSITION_1); } }); // END_INCLUDE (write_to_ui) // BEGIN_INCLUDE (relaunch_activity) // Close the activity activity.finish(); setActivity(null); // Required to force creation of a new activity // Relaunch the activity activity = this.getActivity(); // END_INCLUDE (relaunch_activity) // BEGIN_INCLUDE (check_results) // Verify that the spinner was saved at position 1 final Spinner spinner2 = (Spinner) activity.findViewById(R.id.spinner); int currentPosition = spinner2.getSelectedItemPosition(); assertEquals(TEST_SPINNER_POSITION_1, currentPosition); // END_INCLUDE (check_results) // Since this is a stateful test, we need to make sure that the activity isn't simply // echoing a previously-stored value that (coincidently) matches position 1 final int TEST_SPINNER_POSITION_2 = MainActivity.WEATHER_SNOW; // Set spinner to test position 2 activity.runOnUiThread(new Runnable() { @Override public void run() { spinner2.requestFocus(); spinner2.setSelection(TEST_SPINNER_POSITION_2); } }); // Close the activity activity.finish(); setActivity(null); // Relaunch the activity activity = this.getActivity(); // Verify that the spinner was saved at position 2 final Spinner spinner3 = (Spinner) activity.findViewById(R.id.spinner); currentPosition = spinner3.getSelectedItemPosition(); assertEquals(TEST_SPINNER_POSITION_2, currentPosition); }
Example 16
Source File: ActivityShare.java From XPrivacy with GNU General Public License v3.0 | 4 votes |
@Override protected Throwable doInBackground(String... params) { // Get wakelock PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Toggle"); wl.acquire(); try { // Get data mProgressCurrent = 0; List<Integer> lstUid = mAppAdapter.getListUid(); final String restrictionName = params[0]; int actionId = ((RadioGroup) ActivityShare.this.findViewById(R.id.rgToggle)).getCheckedRadioButtonId(); Spinner spTemplate = ((Spinner) ActivityShare.this.findViewById(R.id.spTemplate)); String templateName = Meta.cTypeTemplate; if (spTemplate.getSelectedItemPosition() > 0) templateName = Meta.cTypeTemplate + spTemplate.getSelectedItemPosition(); for (Integer uid : lstUid) try { if (mAbort) throw new AbortException(ActivityShare.this); // Update progess publishProgress(++mProgressCurrent, lstUid.size() + 1); setState(uid, STATE_RUNNING, null); List<Boolean> oldState = PrivacyManager.getRestartStates(uid, restrictionName); if (actionId == R.id.rbClear) { PrivacyManager.deleteRestrictions(uid, restrictionName, (restrictionName == null)); if (restrictionName == null) { PrivacyManager.deleteUsage(uid); PrivacyManager.deleteSettings(uid); } } else if (actionId == R.id.rbRestrict) { PrivacyManager.setRestriction(uid, restrictionName, null, true, false); PrivacyManager.updateState(uid); } else if (actionId == R.id.rbTemplateCategory) PrivacyManager.applyTemplate(uid, templateName, restrictionName, false, true, false); else if (actionId == R.id.rbTemplateFull) PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, true, false); else if (actionId == R.id.rbTemplateMergeSet) PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, false, false); else if (actionId == R.id.rbTemplateMergeReset) PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, false, true); else if (actionId == R.id.rbEnableOndemand) { PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true)); PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(false)); } else if (actionId == R.id.rbDisableOndemand) { PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(false)); PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(true)); } else Util.log(null, Log.ERROR, "Unknown action=" + actionId); List<Boolean> newState = PrivacyManager.getRestartStates(uid, restrictionName); setState(uid, STATE_SUCCESS, !newState.equals(oldState) ? getString(R.string.msg_restart) : null); } catch (Throwable ex) { setState(uid, STATE_FAILURE, ex.getMessage()); return ex; } } finally { wl.release(); } return null; }
Example 17
Source File: MainActivity.java From RedReader with GNU General Public License v3.0 | 4 votes |
private void openCustomLocation(String[] typeReturnValues, Spinner destinationType, AutoCompleteTextView editText) { final String typeName = typeReturnValues[destinationType.getSelectedItemPosition()]; switch(typeName) { case "subreddit": { final String subredditInput = editText.getText().toString().trim().replace(" ", ""); try { final String normalizedName = RedditSubreddit.stripRPrefix(subredditInput); final RedditURLParser.RedditURL redditURL = SubredditPostListURL.getSubreddit(normalizedName); if(redditURL == null || redditURL.pathType() != RedditURLParser.SUBREDDIT_POST_LISTING_URL) { General.quickToast(this, R.string.mainmenu_custom_invalid_name); } else { onSelected(redditURL.asSubredditPostListURL()); } } catch(InvalidSubredditNameException e){ General.quickToast(this, R.string.mainmenu_custom_invalid_name); } break; } case "user": String userInput = editText.getText().toString().trim().replace(" ", ""); if(!userInput.startsWith("/u/") && !userInput.startsWith("/user/")) { if(userInput.startsWith("u/") || userInput.startsWith("user/")) { userInput = "/" + userInput; } else { userInput = "/u/" + userInput; } } LinkHandler.onLinkClicked(this, userInput); break; case "url": { LinkHandler.onLinkClicked(this, editText.getText().toString().trim()); break; } case "search": { String query = editText.getText().toString().trim(); if (StringUtils.isEmpty(query)) { General.quickToast(this, R.string.mainmenu_custom_empty_search_query); break; } SearchPostListURL url = SearchPostListURL.build(null, query); final Intent intent = new Intent(this, PostListingActivity.class); intent.setData(url.generateJsonUri()); this.startActivity(intent); break; } } }
Example 18
Source File: ConnectionFragment.java From octoandroid with GNU General Public License v3.0 | 4 votes |
private Spinner updateSpinner(ArrayAdapter adapter, Spinner spinner) { int position = spinner.getSelectedItemPosition(); // Gets current position before updating spinner.setAdapter(adapter); setSpinnerSelection(spinner, position); return spinner; }
Example 19
Source File: NewPadActivity.java From padland with Apache License 2.0 | 2 votes |
/** * Almost the same as the previous one. * @param spinner * @return */ private String getPadServerFromSpinner( Spinner spinner ){ return server_url_list[ spinner.getSelectedItemPosition() ]; }
Example 20
Source File: NewPadActivity.java From padland with Apache License 2.0 | 2 votes |
/** * Same as previous but with a spinner * @param spinner * @return */ private String getPadPrefixFromSpinner( Spinner spinner ){ return server_url_prefixed_list[ spinner.getSelectedItemPosition() ]; }