List of usage examples for android.widget AdapterView getSelectedItemPosition
@ViewDebug.CapturedViewProperty public int getSelectedItemPosition()
From source file:com.google.android.demos.jamendo.app.ArtistGalleryActivity.java
/** * {@inheritDoc}// w w w . ja va 2s . c o m */ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == parent.getSelectedItemPosition()) { Uri uri = ContentUris.withAppendedId(Artists.CONTENT_URI, id); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }
From source file:com.google.android.demos.jamendo.app.AlbumGalleryActivity.java
/** * {@inheritDoc}/*from w w w . java 2s . c o m*/ */ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == parent.getSelectedItemPosition()) { Uri uri = ContentUris.withAppendedId(Albums.CONTENT_URI, id); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }
From source file:com.wizard.ui.SimpleSpinnerChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page_spinner, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); //for future use domain name // ((TextView) rootView.findViewById(R.id.ddomain)).setText(Integer.toString(mPage.getmNumberDomainQuestion())); final List<String> severitylist = new ArrayList<String>(); /*/*from www .j a v a2 s. co m*/ severitylist.add("0 = None"); severitylist.add("1 = Mild:symptoms present but causes little distress or disturbance"); severitylist.add("2 = Moderate: some distress or disturbance to patient"); severitylist.add("3 = Severe: major sourcwe of distress or disturbance to patient"); */ //set only numbers severitylist.add("0 = None"); severitylist.add("1 = Mild"); severitylist.add("2 = Moderate"); severitylist.add("3 = Severe"); spinnerSeverity = (Spinner) rootView.findViewById(R.id.spinnerSeverity); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this.getActivity(), // android.R.layout.simple_spinner_item, severitylist); //dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); R.layout.myspinner, severitylist); dataAdapter.setDropDownViewResource(R.layout.myspinner); spinnerSeverity.setAdapter(dataAdapter); spinnerSeverity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { int index = adapterView.getSelectedItemPosition(); mPage.getData().putString("Severity", Integer.toString(index)); mPage.notifyDataChanged(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { int index = adapterView.getSelectedItemPosition(); mPage.getData().putString("Severity", Integer.toString(index)); mPage.notifyDataChanged(); } }); final List<String> frequencylist = new ArrayList<String>(); /* frequencylist.add("1 = Rarely(<1/wk)"); frequencylist.add("2 = Often(1/wk)"); frequencylist.add("3 = Frequent(several times per week)"); frequencylist.add("4 = Very Frequent(daily or all the time)"); */ //set only numbers frequencylist.add("1 = Rarely(<1/wk)"); frequencylist.add("2 = Often(1/wk)"); frequencylist.add("3 = Frequent(several times per week)"); frequencylist.add("4 = Very Frequent(daily or all the time)"); spinnerFrequency = (Spinner) rootView.findViewById(R.id.spinnerFrequency); ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this.getActivity(), // android.R.layout.simple_spinner_dropdown_item, frequencylist); //dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); R.layout.myspinner, frequencylist); dataAdapter2.setDropDownViewResource(R.layout.myspinner); spinnerFrequency.setAdapter(dataAdapter2); spinnerFrequency.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { int index = adapterView.getSelectedItemPosition(); mPage.getData().putString("Frequency", Integer.toString(index)); mPage.notifyDataChanged(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { int index = adapterView.getSelectedItemPosition(); mPage.getData().putString("Frequency", Integer.toString(index)); mPage.notifyDataChanged(); } }); // Pre-select currently selected items. new Handler().post(new Runnable() { @Override public void run() { ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY); if (selectedItems == null || selectedItems.size() == 0) { return; } Set<String> selectedSet = new HashSet<String>(selectedItems); for (int i = 0; i < mChoices.size(); i++) { if (selectedSet.contains(mChoices.get(i))) { //false spinnerSeverity.setItemChecked(i, true); } } } }); return rootView; }
From source file:com.forrestguice.suntimeswidget.LocationDialog.java
protected void initViews(Context context) { WidgetSettings.initDisplayStrings(context); TextView groupTitle = (TextView) findViewById(R.id.appwidget_location_grouptitle); groupTitle.setVisibility(View.GONE); ArrayAdapter<WidgetSettings.LocationMode> spinner_locationModeAdapter; spinner_locationModeAdapter = new ArrayAdapter<WidgetSettings.LocationMode>(myParent, R.layout.layout_listitem_oneline, WidgetSettings.LocationMode.values()); spinner_locationModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_locationMode = (Spinner) findViewById(R.id.appwidget_location_mode); spinner_locationMode.setAdapter(spinner_locationModeAdapter); spinner_locationMode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { final WidgetSettings.LocationMode[] locationModes = WidgetSettings.LocationMode.values(); WidgetSettings.LocationMode locationMode = locationModes[parent.getSelectedItemPosition()]; LocationDialogMode dialogMode = (locationMode == WidgetSettings.LocationMode.CUSTOM_LOCATION) ? LocationDialogMode.MODE_CUSTOM : LocationDialogMode.MODE_AUTO; setMode(dialogMode);// w ww . j a v a2 s . co m } public void onNothingSelected(AdapterView<?> parent) { } }); labl_locationName = (TextView) findViewById(R.id.appwidget_location_name_label); text_locationName = (EditText) findViewById(R.id.appwidget_location_name); labl_locationLat = (TextView) findViewById(R.id.appwidget_location_lat_label); text_locationLat = (EditText) findViewById(R.id.appwidget_location_lat); labl_locationLon = (TextView) findViewById(R.id.appwidget_location_lon_label); text_locationLon = (EditText) findViewById(R.id.appwidget_location_lon); progress_getfix = (ProgressBar) findViewById(R.id.appwidget_location_getfixprogress); progress_getfix.setVisibility(View.GONE); button_getfix = (ImageButton) findViewById(R.id.appwidget_location_getfix); button_getfix.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFixHelper.getFix(); } }); getFixUI = new GetFixUI1(text_locationName, text_locationLat, text_locationLon, progress_getfix, button_getfix); getFixHelper = new GetFixHelper(myParent, getFixUI); if (!getFixHelper.isLocationEnabled()) { button_getfix.setImageResource(GetFixUI.ICON_GPS_DISABLED); } }
From source file:com.forrestguice.suntimeswidget.TimeZoneDialog.java
protected void initViews(Context context, View dialogContent) { WidgetSettings.initDisplayStrings(context); layout_timezone = (LinearLayout) dialogContent.findViewById(R.id.appwidget_timezone_custom_layout); label_timezone = (TextView) dialogContent.findViewById(R.id.appwidget_timezone_custom_label); WidgetTimezones.TimeZoneSort.initDisplayStrings(context); ArrayAdapter<WidgetSettings.TimezoneMode> spinner_timezoneModeAdapter; spinner_timezoneModeAdapter = new ArrayAdapter<WidgetSettings.TimezoneMode>(context, R.layout.layout_listitem_oneline, WidgetSettings.TimezoneMode.values()); spinner_timezoneModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_timezoneMode = (Spinner) dialogContent.findViewById(R.id.appwidget_timezone_mode); spinner_timezoneMode.setAdapter(spinner_timezoneModeAdapter); spinner_timezoneMode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { final WidgetSettings.TimezoneMode[] timezoneModes = WidgetSettings.TimezoneMode.values(); WidgetSettings.TimezoneMode timezoneMode = timezoneModes[parent.getSelectedItemPosition()]; setUseCustomTimezone((timezoneMode == WidgetSettings.TimezoneMode.CUSTOM_TIMEZONE)); setUseSolarTime((timezoneMode == WidgetSettings.TimezoneMode.SOLAR_TIME)); }//from www .ja v a 2 s. c om public void onNothingSelected(AdapterView<?> parent) { } }); View spinner_timezone_empty = dialogContent.findViewById(R.id.appwidget_timezone_custom_empty); label_timezone = (TextView) dialogContent.findViewById(R.id.appwidget_timezone_custom_label); spinner_timezone = (Spinner) dialogContent.findViewById(R.id.appwidget_timezone_custom); spinner_timezone.setEmptyView(spinner_timezone_empty); spinner_timezone.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return triggerTimeZoneActionMode(view); } }); label_timezone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { triggerTimeZoneActionMode(view); } }); label_timezone.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return triggerTimeZoneActionMode(view); } }); layout_solartime = (LinearLayout) dialogContent.findViewById(R.id.appwidget_solartime_layout); label_solartime = (TextView) dialogContent.findViewById(R.id.appwidget_solartime_label); ArrayAdapter<WidgetSettings.SolarTimeMode> spinner_solartimeAdapter; spinner_solartimeAdapter = new ArrayAdapter<WidgetSettings.SolarTimeMode>(context, R.layout.layout_listitem_oneline, WidgetSettings.SolarTimeMode.values()); spinner_solartimeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_solartime = (Spinner) dialogContent.findViewById(R.id.appwidget_solartime); spinner_solartime.setAdapter(spinner_solartimeAdapter); }
From source file:com.code.android.vibevault.SearchScreen.java
private void launchSettingsDialog() { final SeekBar seek; final Spinner sortSpin; final Spinner searchSpin; final TextView seekValue; // Make the settings dialog. AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Search Settings"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_settings_dialog, null); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { }/*from w ww. j a va2 s . c o m*/ }); // Grab all the GUI widgets. seek = (SeekBar) v.findViewById(R.id.NumResultsSeekBar); seek.setProgress(Integer.valueOf(VibeVault.db.getPref("numResults")) - 10); sortSpin = (Spinner) v.findViewById(R.id.SortSpinner); searchSpin = (Spinner) v.findViewById(R.id.SearchSpinner); seekValue = (TextView) v.findViewById(R.id.SeekBarValue); seekValue.setText(VibeVault.db.getPref("numResults")); // Set the seek bar to its current value, and set up a Listener. seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { seekValue.setText(String.valueOf(progress + 10)); VibeVault.db.updatePref("numResults", String.valueOf(progress + 10)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Set up the spinner, and set up it's OnItemSelectedListener. ArrayAdapter<String> sortAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.sortChoices); sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sortSpin.setAdapter(sortAdapter); int sortPos = 1; String sortOrder = VibeVault.db.getPref("sortOrder"); for (int i = 0; i < VibeVault.sortChoices.length; i++) { if (VibeVault.sortChoices[i].equals(sortOrder)) sortPos = i; } sortSpin.setSelection(sortPos); sortSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.db.updatePref("sortOrder", VibeVault.sortChoices[selected]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VibeVault.searchChoices); searchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); searchSpin.setAdapter(searchAdapter); int searchPos = 1; String searchOrder = VibeVault.searchPref; for (int i = 0; i < VibeVault.searchChoices.length; i++) { if (VibeVault.searchChoices[i].equals(searchOrder)) searchPos = i; } searchSpin.setSelection(searchPos); searchSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { int selected = arg0.getSelectedItemPosition(); VibeVault.searchPref = VibeVault.searchChoices[selected]; if (VibeVault.searchPref.equals("Artist") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Artists..."); } else if (VibeVault.searchPref.equals("Show/Artist Description") && artistSearchInput.getText().equals("")) { artistSearchInput.setHint("Search Descriptions..."); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Show the settings screen. ad.setView(v); ad.show(); }