List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:es.ugr.swad.swadroid.modules.downloads.DownloadsManager.java
/** * If there are not groups to which the user belong in the database, it makes the request *//*from w w w .j av a 2 s . c om*/ private void loadGroupsSpinner(List<Group> currentGroups) { if (!currentGroups.isEmpty()) { //there are groups in the selected course, therefore the groups spinner should be loaded Spinner groupsSpinner = (Spinner) this.findViewById(R.id.groupSpinner); groupsSpinner.setVisibility(View.VISIBLE); ArrayList<String> spinnerNames = new ArrayList<String>(currentGroups.size() + 1); spinnerNames.add(getString(R.string.course) + "-" + Courses.getSelectedCourseShortName()); for (Group g : currentGroups) { GroupType gType = dbHelper.getGroupTypeFromGroup(g.getId()); spinnerNames .add(getString(R.string.group) + "-" + gType.getGroupTypeName() + " " + g.getGroupName()); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerNames); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); groupsSpinner.setAdapter(adapter); groupsSpinner.setOnItemSelectedListener(new onGroupSelectedListener()); groupsSpinner.setSelection(groupPosition); } else { this.findViewById(R.id.groupSpinner).setVisibility(View.GONE); getSupportActionBar().setSubtitle(Courses.getSelectedCourseShortName()); } }
From source file:cat.wuyingren.rorhelper.fragments.dialogs.ManageSenatorDialogFragment.java
@NonNull @Override/* ww w .ja v a 2s . c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View v = inflater.inflate(R.layout.dialog_managesenator, null); final TextView randomKillTitle = (TextView) v.findViewById(R.id.managesenator_randomTitle); final ToggleButton randomKillButton = (ToggleButton) v.findViewById(R.id.managesenator_randomToggle); final LinearLayout selectors = (LinearLayout) v.findViewById(R.id.managesenator_selectors); dataSource = MainActivity.getDataSource(); context = MainActivity.getContext(); currentGameId = getArguments().getLong(ARG_GAMEID); killMode = getArguments().getBoolean(ARG_MODE); statesman = getArguments().getBoolean(ARG_TYPE); result.setKill(killMode); result.setStatesman(statesman); final Spinner senatorSpinner = (Spinner) v.findViewById(R.id.managesenator_senatorSpinner); randomKillButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { result.setRandomKill(isChecked); if (isChecked) { selectors.setVisibility(View.GONE); } else { selectors.setVisibility(View.VISIBLE); } } }); if (!killMode) { randomKillTitle.setVisibility(View.GONE); randomKillButton.setVisibility(View.GONE); String[] keys = getArguments().getStringArray(ARG_ARRAY); ArrayList<String> values = getArguments().getStringArrayList(ARG_VALUES); /*ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(MainActivity.getContext(), android.R.layout.simple_spinner_item, keys);*/ SenatorAdapter adapter = new SenatorAdapter(MainActivity.getContext(), android.R.layout.simple_spinner_item, keys, values); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); senatorSpinner.setAdapter(adapter); } else { randomKillTitle.setVisibility(View.VISIBLE); randomKillButton.setVisibility(View.VISIBLE); } senatorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { result.setSenatorID(parent.getSelectedItem().toString()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final Spinner factionSpinner = SystemUtils.configureSpinner(v, R.id.managesenator_factionSpinner, R.array.faction_nameID); factionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { long factionID = dataSource.getFactionId(currentGameId, getResources().getStringArray(R.array.faction_nameID)[position]); result.setFactionID(factionID); if (killMode) { ArrayList<Senator> senators = dataSource.getAllSenatorsOfFaction(factionID); Iterator<Senator> ite = senators.iterator(); ArrayList<CharSequence> array = new ArrayList<CharSequence>(); ArrayList<String> values = new ArrayList<String>(); while (ite.hasNext()) { Senator s = ite.next(); array.add(String.valueOf(s.getId())); values.add(String.valueOf(s.getName())); } String[] keys = new String[array.size()]; keys = array.toArray(keys); //ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item, array); SenatorAdapter adapter = new SenatorAdapter(context, android.R.layout.simple_spinner_item, keys, values); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); senatorSpinner.setAdapter(adapter); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); builder.setView(v).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onManageSenatorDialogPositiveClick(result); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getDialog().cancel(); } }); String stringA, stringB; if (killMode) { stringA = getString(R.string.dialog_managesenator_kill_title); } else { stringA = getString(R.string.dialog_managesenator_title); } if (statesman) { stringB = getString(R.string.statesman); } else { stringB = getString(R.string.senator); } builder.setTitle(stringA + " " + stringB); return builder.create(); }
From source file:open.currency.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setToolbarEnabled(true);/* w ww .j a v a2 s .co m*/ String desGithub = "Visit the <a href='http://openappsproject.github.io/OpenCurrency/'>project page</a> to get more information about OpenCurrency.<br/><br/> 2015 - 2016 OpenAppsProject"; TextView desTV = (TextView) findViewById(R.id.link_github); desTV.setLinksClickable(true); desTV.setMovementMethod(LinkMovementMethod.getInstance()); desTV.setText(Html.fromHtml(desGithub)); currencyArray = getResources().getStringArray(R.array.currencies); currency1 = (EditText) findViewById(R.id.currency1); currency2 = (EditText) findViewById(R.id.currency2); tilCur1 = (TextInputLayout) findViewById(R.id.tilCur1); tilCur2 = (TextInputLayout) findViewById(R.id.tilCur2); Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); Spinner spinner2 = (Spinner) findViewById(R.id.spinner2); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currencies, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); lastEdited = 1; currency1.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { lastEdited = 1; } }); currency2.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { lastEdited = 2; } }); spinner1.setAdapter(adapter); spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { cur1 = position; tilCur1.setHint(currencyArray[position]); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinner2.setAdapter(adapter); spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { cur2 = position; tilCur2.setHint(currencyArray[position]); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); setFabEnabled(true); setFabDrawable(ContextCompat.getDrawable(this, R.drawable.ic_check_white_48dp)); setFabListener(new View.OnClickListener() { Double inputValue = Double.valueOf("0"); @Override public void onClick(View v) { currency1.setEnabled(false); currency2.setEnabled(false); try { if (lastEdited == 1) { inputValue = Double.valueOf(currency1.getText().toString()); } else { inputValue = Double.valueOf(currency2.getText().toString()); } } catch (Exception e) { e.printStackTrace(); } if (inputValue.equals(Double.valueOf("0"))) { Snackbar.make(v, R.string.empty_value, Snackbar.LENGTH_LONG).show(); currency1.setEnabled(true); currency2.setEnabled(true); } else if (cur1 == cur2) { Snackbar.make(v, R.string.sam_cur, Snackbar.LENGTH_LONG).show(); currency1.setEnabled(true); currency2.setEnabled(true); } else { Action<Double> doCalculate = new Action<Double>() { @NonNull @Override public String id() { return "calculate"; } @Nullable @Override protected Double run() throws InterruptedException { if (lastEdited == 1) { return calculate(currencyArray[cur1], currencyArray[cur2], inputValue); } else { return calculate(currencyArray[cur2], currencyArray[cur1], inputValue); } } @Override protected void done(@Nullable Double result) { if (result != null) { if (lastEdited == 1) { currency2.setText(String.valueOf(result)); } else { currency1.setText(String.valueOf(result)); } } currency1.setEnabled(true); currency2.setEnabled(true); } }; doCalculate.execute(); } } }); }
From source file:org.lyricue.android.BibleFragment.java
public void load_bible() { Spinner book = (Spinner) v.findViewById(R.id.spinBibleBook); book.setOnItemSelectedListener(new BookOnItemSelectedListener()); Spinner spin = (Spinner) v.findViewById(R.id.spinBibleChapter); spin.setOnItemSelectedListener(new BookOnItemSelectedListener()); spin = (Spinner) v.findViewById(R.id.spinBibleVerseStart); spin.setOnItemSelectedListener(new BookOnItemSelectedListener()); spin = (Spinner) v.findViewById(R.id.spinBibleVerseEnd); spin.setOnItemSelectedListener(new BookOnItemSelectedListener()); Button b = (Button) v.findViewById(R.id.buttonBibleAdd); b.setOnClickListener(new BibleOnClickListener()); b = (Button) v.findViewById(R.id.buttonBibleShow); b.setOnClickListener(new BibleOnClickListener()); ImageButton ib = (ImageButton) v.findViewById(R.id.imageBibleNext); ib.setOnClickListener(new BibleOnClickListener()); ib = (ImageButton) v.findViewById(R.id.imageBiblePrev); ib.setOnClickListener(new BibleOnClickListener()); // Setup previous verses spinner spin = (Spinner) v.findViewById(R.id.spinBiblePrevious); ArrayAdapter<String> prevAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, prevArray);// w ww .j a va2 s . c o m spin.setAdapter(prevAdapter); spin.setOnItemSelectedListener(new BookOnItemSelectedListener()); new LoadBibleTask().execute(activity); }
From source file:com.remdo.app.EditDeviceActivity.java
private void setsnniper() { Spinner spinner = (Spinner) findViewById(R.id.spinner); // Spinner click listener spinner.setOnItemSelectedListener((OnItemSelectedListener) this); // Spinner Drop down elements List<String> categories = new ArrayList<String>(); if (dh.ODNetworkExists()) { if (EditMode == true) { if (currentDevice.odType == 1) { categories.add("ODNetwork"); categories.add("ODControl"); } else { categories.add("ODControl"); }//from www .j a v a 2s . com } else { categories.add("ODControl"); } } else { if (EditMode == true) { categories.add("ODControl"); categories.add("ODNetwork"); } else { categories.add("ODNetwork"); categories.add("ODControl"); } } // Creating adapter for spinner ArrayAdapter<String> odTypesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories); // Drop down layout style - list view with radio button odTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(odTypesAdapter); //odTypesAdapter.setDropDownViewResource(currentDevice.odType); }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
void updateRoutineSelectionAdapter(final View entryView, Spinner routineSpinner, String[] routineNames) { ArrayAdapter<String> routineAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, routineNames); routineAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); routineSpinner.setAdapter(routineAdapter); }
From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java
/** * Initializes/refreshes the sizes spinner. * /* w ww . j a va 2 s.c o m*/ * Returns: True in case the sizes spinner should be shown. False otherwise. */ protected void setSizeSpinner() { Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_size); if (!mShowSizeFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) { spinner.setVisibility(View.GONE); return; } // Determine which sizes are actually used for the currently // selected status filter. GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter(); final SizeFilter[] usedSizes = gridDatabaseAdapter .getUsedSizes(mArchiveFragmentStatePagerAdapter.getStatusFilter()); // Load the list of descriptions for sizes actually used into the // array adapter. String[] usedSizesDescription = new String[usedSizes.length]; for (int i = 0; i < usedSizes.length; i++) { usedSizesDescription[i] = getResources().getStringArray(R.array.archive_size_filter)[usedSizes[i] .ordinal()]; } ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, usedSizesDescription); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Build the spinner spinner.setAdapter(adapterStatus); // Restore selected size SizeFilter selectedSizeFilter = mArchiveFragmentStatePagerAdapter.getSizeFilter(); for (int i = 0; i < usedSizes.length; i++) { if (usedSizes[i] == selectedSizeFilter) { spinner.setSelection(i); break; } } // Hide spinner if only two choices are available. As one of those // choices is always "ALL" the choices will result in an identical // selection. spinner.setVisibility((usedSizes.length <= 2 ? View.GONE : View.VISIBLE)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Remember currently displayed grid id. int gridId = getCurrentSelectedGridId(); // Get the selected status SizeFilter sizeFilter = usedSizes[(int) id]; // Check if value for status spinner has changed. if (sizeFilter != mArchiveFragmentStatePagerAdapter.getSizeFilter()) { // Refresh pager adapter with new status. mArchiveFragmentStatePagerAdapter.setSizeFilter(sizeFilter); // Refresh the status spinner as the content of the spinners // are related. setStatusSpinner(); // If possible select the grid id which was selected before // changing the spinner(s). Otherwise select last page. selectGridId(gridId); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // Do nothing } }); }
From source file:com.asksven.betterbatterystats.StatsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); super.onCreate(savedInstanceState); // HockeyApp/*w ww. j a v a 2 s . co m*/ try { MetricsManager.register(getApplication()); } catch (Exception e) { Log.e(TAG, e.getMessage()); } //Log.i(TAG, "OnCreated called"); setContentView(R.layout.stats); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.app_name)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayUseLogoEnabled(false); // set debugging if (sharedPrefs.getBoolean("debug_logging", false)) { LogSettings.DEBUG = true; CommonLogSettings.DEBUG = true; } else { LogSettings.DEBUG = false; CommonLogSettings.DEBUG = false; } swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { doRefresh(true); } }); /////////////////////////////////////////////// // check if we have a new release /////////////////////////////////////////////// // if yes do some migration (if required) and show release notes String strLastRelease = sharedPrefs.getString("last_release", "0"); String strCurrentRelease = ""; try { PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); strCurrentRelease = Integer.toString(pinfo.versionCode); } catch (Exception e) { // nop strCurrentRelease is set to "" } // Grant permissions if they are missing and root is available if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) { if ((RootShell.getInstance().isRooted())) { // attempt to set perms using pm-comand Log.i(TAG, "attempting to grant perms with 'pm grant'"); String pkg = this.getPackageName(); RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS"); RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP"); RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS"); if (SysUtils.hasBatteryStatsPermission(this)) { Log.i(TAG, "succeeded"); } else { Log.i(TAG, "failed"); } } } // Package usage stats were introduced in SDK21 so we need to make the distinction if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // show install as system app screen if root available but perms missing if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) { Intent intentSystemApp = new Intent(this, SystemAppActivity.class); this.startActivity(intentSystemApp); } } else { if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) { Intent intentSystemApp = new Intent(this, SystemAppActivity.class); this.startActivity(intentSystemApp); } } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // first start if (strLastRelease.equals("0")) { boolean firstLaunch = !prefs.getBoolean("launched", false); if (firstLaunch) { // Save that the app has been launched SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("launched", true); editor.commit(); // start service to persist reference Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class); this.startService(serviceIntent); // refresh widgets Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE); this.sendBroadcast(intentRefreshWidgets); } SharedPreferences.Editor updater = sharedPrefs.edit(); updater.putString("last_release", strCurrentRelease); updater.commit(); } else if (!strLastRelease.equals(strCurrentRelease)) { // save the current release to properties so that the dialog won't be shown till next version SharedPreferences.Editor updater = sharedPrefs.edit(); updater.putString("last_release", strCurrentRelease); updater.commit(); // we don't need to delete refs as long as we don't change the database schema // Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show(); // ReferenceStore.deleteAllRefs(this); // Intent i = new Intent(this, WriteBootReferenceService.class); // this.startService(i); // i = new Intent(this, WriteUnpluggedReferenceService.class); // this.startService(i); ChangeLog cl = new ChangeLog(this); cl.getLogDialog().show(); } /////////////////////////////////////////////// // retrieve default selections for spinners // if none were passed /////////////////////////////////////////////// m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0")); m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME); if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) { m_refFromName = Reference.BOOT_REF_FILENAME; Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show(); } if (LogSettings.DEBUG) Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName); try { // recover any saved state if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) { m_iStat = (Integer) savedInstanceState.getSerializable("stat"); m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom"); m_refToName = (String) savedInstanceState.getSerializable("stattypeTo"); if (LogSettings.DEBUG) Log.i(TAG, "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName); } } catch (Exception e) { m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0")); m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME); Log.e(TAG, "Exception: " + e.getMessage()); DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle"); DataStorage.LogToFile(LOGFILE, e.getMessage()); DataStorage.LogToFile(LOGFILE, e.getStackTrace()); Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show(); } // Handle the case the Activity was called from an intent with paramaters Bundle extras = getIntent().getExtras(); if ((extras != null) && !extras.isEmpty()) { // Override if some values were passed to the intent if (extras.containsKey(StatsActivity.STAT)) m_iStat = extras.getInt(StatsActivity.STAT); if (extras.containsKey(StatsActivity.STAT_TYPE_FROM)) m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM); if (extras.containsKey(StatsActivity.STAT_TYPE_TO)) m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO); if (LogSettings.DEBUG) Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName); boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false); // Clear the notifications that was clicked to call the activity if (bCalledFromNotification) { NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); nM.cancel(EventWatcherService.NOTFICATION_ID); } } // Spinner for selecting the stat Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat); ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); // android.R.layout.simple_spinner_dropdown_item); spinnerStat.setAdapter(spinnerStatAdapter); // setSelection MUST be called after setAdapter spinnerStat.setSelection(m_iStat); spinnerStat.setOnItemSelectedListener(this); /////////////////////////////////////////////// // Spinner for Selecting the Stat type /////////////////////////////////////////////// Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType); m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item); spinnerStatType.setAdapter(m_spinnerFromAdapter); try { this.setListViewAdapter(); } catch (BatteryInfoUnavailableException e) { Log.e(TAG, "Exception: " + Log.getStackTraceString(e)); Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error, Snackbar.LENGTH_LONG).show(); // Toast.makeText(this, // getString(R.string.info_service_connection_error), // Toast.LENGTH_LONG).show(); } catch (Exception e) { //Log.e(TAG, e.getMessage(), e.fillInStackTrace()); Log.e(TAG, "Exception: " + Log.getStackTraceString(e)); Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show(); } // setSelection MUST be called after setAdapter spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName)); spinnerStatType.setOnItemSelectedListener(this); /////////////////////////////////////////////// // Spinner for Selecting the end sample /////////////////////////////////////////////// Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd); m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item); spinnerStatSampleEnd.setVisibility(View.VISIBLE); spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter); // setSelection must be called after setAdapter if ((m_refToName != null) && !m_refToName.equals("")) { int pos = m_spinnerToAdapter.getPosition(m_refToName); spinnerStatSampleEnd.setSelection(pos); } else { spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME)); } spinnerStatSampleEnd.setOnItemSelectedListener(this); /////////////////////////////////////////////// // sorting /////////////////////////////////////////////// m_iSorting = 0; // log reference store ReferenceStore.logReferences(this); if (LogSettings.DEBUG) { Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName); Log.i(TAG, "OnCreated end"); } }
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
/** * setup filter spinner/*from w ww . jav a 2s .com*/ * * @param ressourceId * @param view * @param spinnerId * @param value */ private void setupSpinnerAdapter(final int ressourceId, final View view, int spinnerId, String value) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(HciDebuggerActivity.this, ressourceId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner sItems = (Spinner) view.findViewById(spinnerId); sItems.setAdapter(adapter); sItems.setSelection(getIndex(sItems, value)); sItems.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view2, int position, long id) { if (!sItems.getSelectedItem().toString().equals(getResources().getString(R.string.filter_choose))) { SharedPreferences.Editor editor = prefs.edit(); if (ressourceId == R.array.packet_type_array) { if (sItems.getSelectedItem().toString().equals(Constants.HCI_EVENT)) { displayEventSpinner(view); } else { displayCmdSpinner(view); } filters.setPacketType(sItems.getSelectedItem().toString()); editor.putString(Constants.PREFERENCES_PACKET_TYPE_FILTER, sItems.getSelectedItem().toString()); editor.commit(); } else if (ressourceId == R.array.event_type_array) { if (sItems.getSelectedItem().toString().equals(Constants.HCI_LE_META)) { displaySubEventSpinner(view); } filters.setEventType(sItems.getSelectedItem().toString()); editor.putString(Constants.PREFERENCES_EVENT_TYPE_FILTER, sItems.getSelectedItem().toString()); editor.commit(); } else if (ressourceId == R.array.ogf_array) { filters.setOgf(sItems.getSelectedItem().toString()); editor.putString(Constants.PREFERENCES_OGF_FILTER, sItems.getSelectedItem().toString()); editor.commit(); } else if (ressourceId == R.array.subevent_array) { if (sItems.getSelectedItem().toString().equals(Constants.HCI_ADVERTISING_REPORT)) { displayAdvertizingReportFilter(view); } filters.setSubEventType(sItems.getSelectedItem().toString()); editor.putString(Constants.PREFERENCES_SUBEVENT_FILTERS, sItems.getSelectedItem().toString()); editor.commit(); } } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java
/** * Initializes/refreshes the status spinner. * //from w ww .jav a2 s.c o m * Returns: True in case the status spinner should be shown. False * otherwise. */ protected void setStatusSpinner() { Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_status); if (!mShowStatusFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) { spinner.setVisibility(View.GONE); return; } // Determine which statuses are actually used for the currently // selected size filter. GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter(); final StatusFilter[] usedStatuses = gridDatabaseAdapter .getUsedStatuses(mArchiveFragmentStatePagerAdapter.getSizeFilter()); // Load the list of descriptions for statuses actually used into the // array adapter. String[] usedStatusesDescription = new String[usedStatuses.length]; for (int i = 0; i < usedStatuses.length; i++) { usedStatusesDescription[i] = getResources() .getStringArray(R.array.archive_status_filter)[usedStatuses[i].ordinal()]; } ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, usedStatusesDescription); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Build the spinner spinner.setAdapter(adapterStatus); // Restore selected status StatusFilter selectedStatusFilter = mArchiveFragmentStatePagerAdapter.getStatusFilter(); for (int i = 0; i < usedStatuses.length; i++) { if (usedStatuses[i] == selectedStatusFilter) { spinner.setSelection(i); break; } } // Hide spinner if only two choices are available. As one of those // choices is always "ALL" the choices will result in an identical // selection. spinner.setVisibility((usedStatuses.length <= 2 ? View.GONE : View.VISIBLE)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Get the selected status StatusFilter statusFilter = usedStatuses[(int) id]; // Check if value for status spinner has changed. if (statusFilter != mArchiveFragmentStatePagerAdapter.getStatusFilter()) { // Remember currently displayed grid id. int gridId = getCurrentSelectedGridId(); // Refresh pager adapter with new status. mArchiveFragmentStatePagerAdapter.setStatusFilter(statusFilter); // Refresh the size spinner as the content of the spinners // are related. setSizeSpinner(); // If possible select the grid id which was selected before // changing the spinner(s). Otherwise select last page. selectGridId(gridId); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // Do nothing } }); }