List of usage examples for android.widget ArrayAdapter getPosition
public int getPosition(@Nullable T item)
From source file:com.google.android.apps.flexbox.MainActivity.java
private void initializeSpinner(int currentValue, int menuItemId, Menu navigationMenu, int arrayResourceId, AdapterView.OnItemSelectedListener listener, ValueToStringConverter converter) { Spinner spinner = (Spinner) MenuItemCompat.getActionView(navigationMenu.findItem(menuItemId)); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayResourceId, R.layout.spinner_item);/*from w w w.ja va 2 s . c om*/ spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(listener); String selectedAsString = converter.asString(currentValue); int position = adapter.getPosition(selectedAsString); spinner.setSelection(position); }
From source file:de.unipassau.isl.evs.ssh.app.activity.EditUserDeviceFragment.java
/** * Creates and shows a dialogs that gives the user the option to edit a group. *///from w ww . ja v a 2 s . c o m private void showEditUserDeviceDialog(Bundle bundle) { final UserDevice userDevice = (UserDevice) bundle.getSerializable(EDIT_USERDEVICE_DIALOG); if (userDevice == null) { Log.i(TAG, "No device found."); return; } final String[] groupNames = bundle.getStringArray(ALL_GROUPS_DIALOG); if (groupNames == null) { Log.i(TAG, "Empty bundle"); return; } final AppUserConfigurationHandler handler = getComponent(AppUserConfigurationHandler.KEY); if (handler == null) { Log.i(TAG, "Container not yet connected!"); return; } final LayoutInflater inflater = getActivity().getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.dialog_edituserdevice, null); final TextView title = (TextView) dialogView.findViewById(R.id.editdevicedialog_title); title.setText(String.format(getResources().getString(R.string.edit_user_device), userDevice.getName())); final EditText userDeviceName = (EditText) dialogView.findViewById(R.id.editdevicedialog_username); userDeviceName.setText(userDevice.getName()); final ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, groupNames); final Spinner groupName = ((Spinner) dialogView.findViewById(R.id.editdevicedialog_spinner)); groupName.setAdapter(adapter); groupName.setSelection(adapter.getPosition(userDevice.getInGroup())); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final Resources res = getResources(); final AlertDialog editDialog = builder.setView(dialogView).setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.edit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { final AppMainActivity activity = (AppMainActivity) getActivity(); if (activity.hasPermission(Permission.CHANGE_USER_NAME) && activity.hasPermission(Permission.CHANGE_USER_GROUP)) { String name = userDeviceName.getText().toString(); String group = ((String) groupName.getSelectedItem()); DeviceID userDeviceID = userDevice.getUserDeviceID(); // no permission check as method only gets called when user can edit user name / user group handler.setUserName(userDeviceID, name); handler.setUserGroup(userDeviceID, group); } else { showToast(R.string.you_can_not_edit_user_devices); } } }).setNeutralButton(R.string.remove, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (((AppMainActivity) getActivity()).hasPermission(Permission.DELETE_USER)) { handler.removeUserDevice(userDevice.getUserDeviceID()); String toastText = String.format(res.getString(R.string.device_removed), userDevice.getName()); Toast.makeText(getActivity(), toastText, Toast.LENGTH_SHORT).show(); } else { showToast(R.string.you_can_not_remove_users); } } }).create(); // open the soft keyboard when dialog gets focused userDeviceName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { editDialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); editDialog.show(); userDeviceName.requestFocus(); }
From source file:com.quaap.audiometer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pref = getApplicationContext().getSharedPreferences("main", MODE_PRIVATE); mMeterView = (MeterView) findViewById(R.id.meterLayout); mMicLevelReader = new MicLevelReader(this, LevelMethod.dBFS); ImageButton show_ctrls = (ImageButton) findViewById(R.id.show_ctrls); show_ctrls.setOnClickListener(new View.OnClickListener() { @Override/*ww w .j a v a 2s .com*/ public void onClick(View view) { ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls); ctrls.showNext(); } }); ImageButton hide_ctrls = (ImageButton) findViewById(R.id.hide_ctrls); hide_ctrls.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls); ctrls.showPrevious(); } }); final SeekBar scaleCtrl = (SeekBar) findViewById(R.id.scaleCtrl); scaleCtrl.setProgress(pref.getInt("scaleCtrl", scaleCtrl.getProgress())); setScale(); scaleCtrl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { setScale(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); final ToggleButton onoff = (ToggleButton) findViewById(R.id.toggleButton); onoff.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (onoff.isChecked()) { if (!startit()) { onoff.setChecked(false); } } else { stopit(); } } }); LevelMethod levM = LevelMethod.valueOf(pref.getString("levelMethod", LevelMethod.dBFS.toString())); final Spinner levelType = (Spinner) findViewById(R.id.levelType); ArrayAdapter<LevelMethod> levelTypeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, LevelMethod.values()); levelType.setAdapter(levelTypeAdapter); levelType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { LevelMethod lmeth = (LevelMethod) adapterView.getSelectedItem(); levelMethodChanged(lmeth); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); levelType.setSelection(levelTypeAdapter.getPosition(levM)); levelMethodChanged((LevelMethod) levelType.getSelectedItem()); checkMicrophoneAccess(); }
From source file:com.akhbulatov.wordkeeper.ui.activity.MainActivity.java
private void showWordEditorDialog(@StringRes int titleId, @StringRes int positiveTextId, @StringRes int negativeTextId) { DialogFragment dialog = WordEditorDialog.newInstance(titleId, positiveTextId, negativeTextId); dialog.show(getSupportFragmentManager(), null); // NOTE! If the method is not called, the app crashes getSupportFragmentManager().executePendingTransactions(); Dialog dialogView = dialog.getDialog(); Spinner spinnerCategories = dialogView.findViewById(R.id.spinner_categories); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mWordListFragment.getCategories()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerCategories.setAdapter(adapter); // Receives and shows data of the selected word to edit in the dialog // Data is the name, translation and category if (positiveTextId == R.string.word_editor_action_edit) { EditText editName = dialogView.findViewById(R.id.edit_word_name); EditText editTranslation = dialogView.findViewById(R.id.edit_word_translation); editName.setText(mWordListFragment.getName()); editTranslation.setText(mWordListFragment.getTranslation()); spinnerCategories.setSelection(adapter.getPosition(mWordListFragment.getCategory())); }/*from www . j av a2 s .c o m*/ }
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditExpenseActivity.java
@Override protected void onStart() { super.onStart(); if (expense.getName() != null) { expenseNameInput.setText(expense.getName()); } else {/*from www . j av a 2 s .c o m*/ expenseNameInput.setText(expenseName); } if (expense.getDes() != null) { expenseDescriptionInput.setText(expense.getDes().toString()); } if (expense.getCost() != null) { expenseCostInput.setText(expense.getCost().toString()); } if (expense.getDate() != null) { date.setText(sdf.format(expense.getDate())); } expenseNameInput.addTextChangedListener(this); if (expense.getDate() != null) { date.setText(sdf.format(expense.getDate())); } ArrayAdapter<CharSequence> currencyAdaptor = ArrayAdapter.createFromResource(this, R.array.CurrencyArray, R.layout.spinner_item); currencyAdaptor.setDropDownViewResource(R.layout.spinner_dropdown_item); currencySpinner.setAdapter(currencyAdaptor); ArrayAdapter<CharSequence> categoryAdaptor = ArrayAdapter.createFromResource(this, R.array.CategoryArray, R.layout.spinner_item); categoryAdaptor.setDropDownViewResource(R.layout.spinner_dropdown_item); categorySpinner.setAdapter(categoryAdaptor); currencySpinner.setSelection(currencyAdaptor.getPosition(expense.getCurr())); categorySpinner.setSelection(categoryAdaptor.getPosition(expense.getCat())); setEditable(); }
From source file:joshuatee.wx.ModelInterfaceActivity.java
@SuppressWarnings("unchecked") public void addItemsOnSpinner3() { spinner_sector = (Spinner) findViewById(R.id.spinner_sector); String[] list_sector_arr = new String[] { "US", "CGP", "SGP", "SE", "NE", "SW", "NW" }; ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list_sector_arr);/*from w w w . j av a 2s. co m*/ dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_sector.setAdapter(dataAdapter); sector = preferences3.getString("MODEL_SECTOR_LAST_USED", "US"); ArrayAdapter<String> myAdap = (ArrayAdapter<String>) spinner_sector.getAdapter(); //cast to an ArrayAdapter spinnerPosition = myAdap.getPosition(sector); spinner_sector.setSelection(spinnerPosition); }
From source file:joshuatee.wx.ModelInterfaceActivity.java
@SuppressWarnings("unchecked") public void addItemsOnSpinner3NAM4KM() { spinner_sector = (Spinner) findViewById(R.id.spinner_sector); list_sector = new ArrayList<String>(); list_sector.add("US"); list_sector.add("SGP"); list_sector.add("CGP"); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list_sector);//w w w .j a v a 2s .co m dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_sector.setAdapter(dataAdapter); sector = preferences3.getString("MODEL_SECTOR_LAST_USED", "SE"); ArrayAdapter<String> myAdap = (ArrayAdapter<String>) spinner_sector.getAdapter(); //cast to an ArrayAdapter spinnerPosition = myAdap.getPosition(sector); spinner_sector.setSelection(spinnerPosition); }
From source file:joshuatee.wx.ModelInterfaceActivity.java
@SuppressWarnings("unchecked") public void addItemsOnSpinner3Sref() { spinner_sector = (Spinner) findViewById(R.id.spinner_sector); list_sector = new ArrayList<String>(); list_sector.add("US"); list_sector.add("CGP"); list_sector.add("SGP"); list_sector.add("SE"); list_sector.add("NE"); list_sector.add("SW"); list_sector.add("CAN"); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list_sector);//www .j a va 2 s . c om dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_sector.setAdapter(dataAdapter); sector = preferences3.getString("MODEL_SECTOR_LAST_USED", "US"); ArrayAdapter<String> myAdap = (ArrayAdapter<String>) spinner_sector.getAdapter(); //cast to an ArrayAdapter spinnerPosition = myAdap.getPosition(sector); spinner_sector.setSelection(spinnerPosition); }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateSecondForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title))); EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY); passwordEditText.setTransformationMethod(new PasswordTransformationMethod()); formLayout.addView(passwordEditText); formLayout.addView(createErrorView(PASSWORD_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);//from w w w. j av a2s .com params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array, android.R.layout.simple_spinner_item); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(GENDER_KEY, adapter.getItem(pos).toString()); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); if (mFormData.get(GENDER_KEY) != null) { spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY))); } formLayout.addView(spinner); }
From source file:com.cybussolutions.wikki.afri_pay.SignUp.java
@SuppressLint("NewApi") @Override//from w w w. j a va 2s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_up); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); android.support.v7.app.ActionBar ab = getSupportActionBar(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Enable the Up button if (ab != null) { ab.setHomeAsUpIndicator(R.drawable.ic_back); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle("Registration"); } // BugSenseHandler.initAndStartSession(this, "1c9ce82c"); // chromeHelpPopup = new ChromeHelpPopup(SignUp.this, "Password should contain capital and small alphabets, one number and one special character. Example: Cybus@12"); // SelectedDateView = (TextView) findViewById(R.id.DatePickerInput); // imageView=(ImageView)findViewById(R.id.signup_imageView); firstname = (EditText) findViewById(R.id.signup_firstName); lastname = (EditText) findViewById(R.id.signup_lastName); email = (EditText) findViewById(R.id.signup_email); mobile = (EditText) findViewById(R.id.signup_mobile); gender = (RadioGroup) findViewById(R.id.genderRG); gender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.mrRB: { genderText = "Male"; title = "Mr"; break; } case R.id.missRB: { genderText = "Female"; title = "Miss"; break; } case R.id.mrsRB: { genderText = "Female"; title = "Mrs"; break; } default: { break; } } } }); // idNo=(EditText) findViewById(R.id.signup_idNum); /* buttonchoose=(Button) findViewById(R.id.uploadimage); buttonchoose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // openGallery(v); } });*/ try { Button b = (Button) findViewById(R.id.signup_register); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub submit(v); } }); } Button cancel = (Button) findViewById(R.id.signup_cancel); if (cancel != null) { cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } } catch (Exception e) { e.printStackTrace(); } /* doctype=(RadioGroup) findViewById(R.id.signup_doctype); doctype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.signup_passport: value = "Passport"; typeid="5"; break; case R.id.signup_license: value = "Driving License"; typeid="4"; break; } } });*/ String COmpare = "United Kingdom"; CountriesObjects = new ArrayList<>(); CountriesName = new ArrayList<>(); DataBase DataBase = new DataBase(SignUp.this); CountriesObjects = DataBase.getCountriesDB(""); for (int i = 0; i < CountriesObjects.size(); i++) { CountriesName.add(CountriesObjects.get(i).getCountry_name()); } country = (Spinner) findViewById(R.id.signup_countries_spinner); ArrayAdapter adapter201 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, CountriesName); country.setAdapter(adapter201); if (!COmpare.equals(null)) { int spinnerPosition = adapter201.getPosition(COmpare); country.setSelection(spinnerPosition); } country.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub // InputMethodManager inputMethodManager = (InputMethodManager) // getSystemService(Activity.INPUT_METHOD_SERVICE); // inputMethodManager.hideSoftInputFromWindow(getCurrentFocus() // .getWindowToken(), 0); return false; } }); country.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long arg3) { // TODO Auto-generated method stub countrycode = (TextView) findViewById(R.id.signup_code); countrycode.setText("+" + CountriesObjects.get(pos).getCalling_code()); countrycode.setEnabled(false); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); // user_name = (EditText) findViewById(R.id.signup_userName); password = (EditText) findViewById(R.id.signup_password); re_password = (EditText) findViewById(R.id.signup_confirmpassword); re_password.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub EditText e = (EditText) findViewById(R.id.signup_password); String pass = e.getText().toString(); TextView d = (TextView) findViewById(R.id.matchPassword); if (!pass.contentEquals(s)) { d.setText("Passwords Do not Match"); d.setVisibility(View.VISIBLE); } else { d.setVisibility(View.GONE); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); }