List of usage examples for android.widget ArrayAdapter getPosition
public int getPosition(@Nullable T item)
From source file:mobile.tiis.appv2.helpers.Utils.java
public static void setSpinnerSelection(Spinner spinner, String value) { @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter(); int spinnerPosition = adapter.getPosition(value); spinner.setSelection(spinnerPosition); }
From source file:org.totschnig.myexpenses.dialog.DialogUtils.java
public static Spinner configureCurrencySpinner(View view, Context context, AdapterView.OnItemSelectedListener listener) { Spinner spinner = (Spinner) view.findViewById(R.id.Currency); ArrayAdapter<CurrencyEnum> curAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, android.R.id.text1, CurrencyEnum.sortedValues()); curAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(curAdapter);/*from w w w . j a va 2s . c om*/ spinner.setOnItemSelectedListener(listener); spinner.setSelection( curAdapter.getPosition(CurrencyEnum.valueOf(Utils.getLocalCurrency().getCurrencyCode()))); return spinner; }
From source file:me.priyesh.chromasample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); setSupportActionBar(mToolbar);//from ww w. j a v a 2s. c o m int statusBarHeight = statusBarHeight(); mToolbar.setPadding(0, statusBarHeight, 0, 0); mToolbar.getLayoutParams().height += statusBarHeight; mColor = savedInstanceState != null ? savedInstanceState.getInt(KEY_COLOR) : ContextCompat.getColor(this, R.color.colorPrimary); ColorMode colorMode = savedInstanceState != null ? ColorMode.valueOf(savedInstanceState.getString(KEY_COLOR_MODE)) : ColorMode.RGB; ArrayAdapter<ColorMode> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, ColorMode.values()); mColorModeSpinner.setAdapter(adapter); mColorModeSpinner.setSelection(adapter.getPosition(colorMode)); updateTextView(mColor); updateToolbar(mColor, mColor); }
From source file:org.jboss.aerogear.android.cookbook.aerodoc.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); application = (AeroDocApplication) getApplication(); contentPanel = findViewById(R.id.contentPanel); availableLeadsFragments = new AvailableLeadsFragments(); acceptedLeadsFragments = new AcceptedLeadsFragments(); // -- Dropdown (Status) Spinner spinner = (Spinner) findViewById(R.id.status); ArrayAdapter<String> spinnerAdapter = (ArrayAdapter) spinner.getAdapter(); int actualStatus = spinnerAdapter.getPosition(application.getSaleAgent().getStatus()); spinner.setSelection(actualStatus, true); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*w ww . ja v a 2 s . c o m*/ public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { String status = (String) adapterView.getItemAtPosition(position); if (!application.getSaleAgent().getStatus().equals(status)) { updateStatus(status); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // -- Tabs (Leads - Available & Archived) ViewPager pager = (ViewPager) findViewById(R.id.pager); TabLayout tabs = (TabLayout) findViewById(R.id.tabs); pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager())); tabs.setupWithViewPager(pager); }
From source file:de.nico.ha_manager.activities.AddHomework.java
private void handleIntent(Intent intent) { Bundle extras = intent.getExtras();/*w w w. j av a 2 s . c o m*/ if (extras != null) { // Set ID ID = extras.getString(Source.allColumns[0]); // Set Urgent if (!extras.getString(Source.allColumns[1]).equals("")) { CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox_urgent); checkBox.setChecked(true); } // Set Subject String subject = extras.getString(Source.allColumns[2]); Spinner subSpin = (Spinner) findViewById(R.id.spinner_subject); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, subjects); // Get position in subject list int spinnerPostion = adapter.getPosition(subject); // If subject is not in subject list if (spinnerPostion == -1) { int size = subjects.length; String[] tmp = new String[size + 1]; System.arraycopy(subjects, 0, tmp, 0, size); tmp[size] = subject; Arrays.sort(tmp); subjects = tmp; setSpinner(); adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, subjects); spinnerPostion = adapter.getPosition(subject); } subSpin.setSelection(spinnerPostion); // Set Homework EditText hwEdit = (EditText) findViewById(R.id.editText_homework); hwEdit.setText(extras.getString(Source.allColumns[3])); // Set Until Button untilButton = (Button) findViewById(R.id.button_until); untilButton.setText(extras.getString(Source.allColumns[4])); until = extras.getString(Source.allColumns[4]); } }
From source file:ca.rmen.android.networkmonitor.app.prefs.SelectFieldsActivity.java
private void selectColumns(String[] columnNames) { for (int i = 0; i < mListView.getCount(); i++) mListView.setItemChecked(i, false); @SuppressWarnings("unchecked") ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mListView.getAdapter(); for (String columnName : columnNames) { String columnLabel = NetMonColumns.getColumnLabel(this, columnName); int position = adapter.getPosition(columnLabel); mListView.setItemChecked(position, true); }/*from ww w. jav a2 s . co m*/ }
From source file:me.johnmh.boogdroid.ui.BugStatusFragment.java
@NonNull private Spinner setupSpinnerResolution(View view) { Spinner spinnerResolution = (Spinner) view.findViewById(R.id.resolution); BugResolutionChanges resolutionValues = bug.getProduct().getServer().getResolutionValues(); ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity().getBaseContext(), android.R.layout.simple_spinner_item, resolutionValues); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerResolution.setAdapter(adapter); spinnerResolution.setSelection(adapter.getPosition(bug.getResolution())); return spinnerResolution; }
From source file:me.johnmh.boogdroid.ui.BugStatusFragment.java
@NonNull private Spinner setupStatusSpinner(View view) { Spinner spinnerStatus = (Spinner) view.findViewById(R.id.status); String statusName = bug.getStatus(); Server server = bug.getProduct().getServer(); StatusInfo statusInfo = server.getStatusChanges().get(statusName); ArrayAdapter<ChangeStatusInfo> adapter = new ArrayAdapter<>(getActivity().getBaseContext(), android.R.layout.simple_spinner_item, statusInfo.getChangeList()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerStatus.setAdapter(adapter);/* w w w .jav a2 s . c om*/ spinnerStatus.setSelection(adapter.getPosition(server.findChangeStatusInfo(statusName))); return spinnerStatus; }
From source file:net.alchemiestick.katana.winehqappdb.filter_dialog.java
private void setupSpinner(int spId, int arrayId, String cur, AdapterView.OnItemSelectedListener listener) { Spinner sp = (Spinner) findViewById(spId); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(cx, arrayId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp.setAdapter(adapter);/*from w ww. j ava 2 s . c om*/ int pos = adapter.getPosition(cur); sp.setSelection(pos); sp.setOnItemSelectedListener(listener); }
From source file:net.alexjf.tmm.fragments.MoneyNodeEditorFragment.java
private void updateNodeFields() { // If we are adding a new node, reset all fields if (node == null) { nameText.setText(""); descriptionText.setText(""); iconSelectorButton.setDrawableId(0); creationDateButton.setText(dateFormat.format(new Date())); initialBalanceText.setText(""); PreferenceManager prefManager = PreferenceManager.getInstance(); String prefCurrency = prefManager.readUserStringPreference(PREFKEY_DEFAULTCURRENCY, null); int positionInSpinner = 0; if (prefCurrency != null) { @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = (ArrayAdapter<String>) currencySpinner.getAdapter(); positionInSpinner = adapter.getPosition(prefCurrency); }//w w w . j ava 2s. co m currencySpinner.setSelection(positionInSpinner); addButton.setText(R.string.add); // If we are editing a node, fill fields with current information } else { try { node.load(); nameText.setText(node.getName()); descriptionText.setText(node.getDescription()); selectedDrawableName = node.getIcon(); int iconId = DrawableResolver.getInstance().getDrawableId(selectedDrawableName); iconSelectorButton.setDrawableId(iconId); creationDateButton.setText(dateFormat.format(node.getCreationDate())); initialBalanceText.setText(node.getInitialBalance().getAmount().toString()); @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = (ArrayAdapter<String>) currencySpinner.getAdapter(); int positionInSpinner = adapter.getPosition(node.getCurrency().getCurrencyCode()); currencySpinner.setSelection(positionInSpinner); } catch (DatabaseException e) { Log.e("TMM", e.getMessage(), e); } addButton.setText(R.string.edit); } }