List of usage examples for android.widget ArrayAdapter setDropDownViewResource
public void setDropDownViewResource(@LayoutRes int resource)
Sets the layout resource to create the drop down views.
From source file:com.yschi.castscreen.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mResultCode = savedInstanceState.getInt(STATE_RESULT_CODE); mResultData = savedInstanceState.getParcelable(STATE_RESULT_DATA); }/* w w w .j ava2s.c o m*/ mContext = this; mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); mDiscoverdMap = new HashMap<>(); mDiscoverListView = (ListView) findViewById(R.id.discover_listview); mDiscoverAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); mDiscoverAdapter.addAll(mDiscoverdMap.keySet()); mDiscoverListView.setAdapter(mDiscoverAdapter); mDiscoverListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String name = mDiscoverAdapter.getItem(i); String ip = mDiscoverdMap.get(name); Log.d(TAG, "Select receiver name: " + name + ", ip: " + ip); mReceiverIp = ip; updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } }); // add server mode option mDiscoverAdapter.add(mContext.getString(R.string.server_mode)); mDiscoverdMap.put(mContext.getString(R.string.server_mode), ""); mReceiverTextView = (TextView) findViewById(R.id.receiver_textview); final EditText ipEditText = (EditText) findViewById(R.id.ip_edittext); final Button selectButton = (Button) findViewById(R.id.select_button); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (ipEditText.getText().length() > 0) { mReceiverIp = ipEditText.getText().toString(); Log.d(TAG, "Using ip: " + mReceiverIp); updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit() .putString(PREF_KEY_INPUT_RECEIVER, mReceiverIp).commit(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } } }); ipEditText.setText(mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_INPUT_RECEIVER, "")); Spinner formatSpinner = (Spinner) findViewById(R.id.format_spinner); ArrayAdapter<CharSequence> formatAdapter = ArrayAdapter.createFromResource(this, R.array.format_options, android.R.layout.simple_spinner_item); formatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); formatSpinner.setAdapter(formatAdapter); formatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedFormat = FORMAT_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedFormat = FORMAT_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, 0).commit(); } }); formatSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_FORMAT, 0)); Spinner resolutionSpinner = (Spinner) findViewById(R.id.resolution_spinner); ArrayAdapter<CharSequence> resolutionAdapter = ArrayAdapter.createFromResource(this, R.array.resolution_options, android.R.layout.simple_spinner_item); resolutionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); resolutionSpinner.setAdapter(resolutionAdapter); resolutionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedWidth = RESOLUTION_OPTIONS[i][0]; mSelectedHeight = RESOLUTION_OPTIONS[i][1]; mSelectedDpi = RESOLUTION_OPTIONS[i][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedWidth = RESOLUTION_OPTIONS[0][0]; mSelectedHeight = RESOLUTION_OPTIONS[0][1]; mSelectedDpi = RESOLUTION_OPTIONS[0][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, 0).commit(); } }); resolutionSpinner .setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_RESOLUTION, 0)); Spinner bitrateSpinner = (Spinner) findViewById(R.id.bitrate_spinner); ArrayAdapter<CharSequence> bitrateAdapter = ArrayAdapter.createFromResource(this, R.array.bitrate_options, android.R.layout.simple_spinner_item); bitrateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bitrateSpinner.setAdapter(bitrateAdapter); bitrateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedBitrate = BITRATE_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedBitrate = BITRATE_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, 0).commit(); } }); bitrateSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_BITRATE, 0)); mReceiverIp = mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_RECEIVER, ""); updateReceiverStatus(); startService(); }
From source file:com.mifos.mifosxdroid.online.CreateNewClientFragment.java
private void inflateOfficeSpinner() { showProgress(true);//from w w w .ja va 2s . c o m App.apiManager.getOffices(new Callback<List<Office>>() { @Override public void success(List<Office> offices, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; final List<String> officeList = new ArrayList<String>(); for (Office office : offices) { officeList.add(office.getName()); officeNameIdHashMap.put(office.getName(), office.getId()); } ArrayAdapter<String> officeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, officeList); officeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_offices.setAdapter(officeAdapter); sp_offices.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { officeId = officeNameIdHashMap.get(officeList.get(i)); Log.d("officeId " + officeList.get(i), String.valueOf(officeId)); if (officeId != -1) { inflateStaffSpinner(officeId); } else { Toast.makeText(getActivity(), getString(R.string.error_select_office), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); } }); }
From source file:com.example.android.pets.EditorActivity.java
/** * Setup the dropdown spinner that allows the user to select the gender of the pet. *///from w w w . j av a 2s . com private void setupSpinner() { // Create adapter for spinner. The list options are from the String array it will use // the spinner will use the default layout ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options, android.R.layout.simple_spinner_item); // Specify dropdown layout style - simple list view with 1 item per line genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); // Apply the adapter to the spinner mGenderSpinner.setAdapter(genderSpinnerAdapter); // Set the integer mSelected to the constant values mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)) { if (selection.equals(getString(R.string.gender_male))) { mGender = PetEntry.GENDER_MALE; } else if (selection.equals(getString(R.string.gender_female))) { mGender = PetEntry.GENDER_FEMALE; } else { mGender = PetEntry.GENDER_UNKNOWN; } } } // Because AdapterView is an abstract class, onNothingSelected must be defined @Override public void onNothingSelected(AdapterView<?> parent) { mGender = PetEntry.GENDER_UNKNOWN; } }); }
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 .j av a 2 s . com*/ 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.mbientlab.metawear.app.CustomFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ((TextView) view.findViewById(R.id.config_option_title)).setText(R.string.config_name_sensor_fusion_data); fusionModeSelection = (Spinner) view.findViewById(R.id.config_option_spinner); fusionModeSelection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from w w w.ja v a 2s . c o m public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { srcIndex = position; final YAxis leftAxis = chart.getAxisLeft(); if (position == 0) { leftAxis.setAxisMaxValue(1.f); leftAxis.setAxisMinValue(-1.f); } else { leftAxis.setAxisMaxValue(360f); leftAxis.setAxisMinValue(-360f); } refreshChart(false); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(), R.array.values_fusion_data, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fusionModeSelection.setAdapter(spinnerAdapter); askPermission(); }
From source file:net.net76.lifeiq.TaskiQ.RegisterActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); inputFirstname = (EditText) findViewById(R.id.firstname); inputSurname = (EditText) findViewById(R.id.surname); inputUserID = (EditText) findViewById(R.id.userID); inputEmail = (EditText) findViewById(R.id.email); //1 inputPassword = (EditText) findViewById(R.id.password); //1inputPassword2 = (EditText) findViewById(R.id.password2); Spinner spinner = (Spinner) findViewById(R.id.spinner); EULA = (TextView) findViewById(R.id.EULA); SpannableString content = new SpannableString(EULA.getText().toString()); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); EULA.setText(content);/*from w ww . j a va 2 s .c om*/ EULA.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PackageInfo versionInfo = getPackageInfo(); // EULA title String title = RegisterActivity.this.getString(R.string.app_name) + " v " + versionInfo.versionName; // EULA text String message = RegisterActivity.this.getString(R.string.eula_string); android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(RegisterActivity.this) .setTitle(title).setMessage(message).setCancelable(false) .setPositiveButton(R.string.accept, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { EULAAccept = true; // Close dialog dialogInterface.dismiss(); } }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EULAAccept = false; } }); builder.create().show(); } }); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Country_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Log.v("item", (String) parent.getItemAtPosition(position)); countryString = (String) parent.getItemAtPosition(position); } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); btnRegister = (Button) findViewById(R.id.btnRegister); btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen); // Progress dialog pDialog = new ProgressDialog(this); //pDialog.setCancelable(false); pDialog.setCanceledOnTouchOutside(false); // Session manager session = new SessionManager(getApplicationContext()); // SQLite database handler db = new SQLiteHandler(getApplicationContext()); // Check if user is already logged in or not if (session.isLoggedIn()) { // User is already logged in. Take him to main activity Intent intent = new Intent(RegisterActivity.this, MainActivity.class); startActivity(intent); finish(); } // Register Button Click event btnRegister.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { String Firstname = inputFirstname.getText().toString(); String Surname = inputSurname.getText().toString(); String UserID = inputUserID.getText().toString(); String email = inputEmail.getText().toString(); //1 String password = inputPassword.getText().toString(); //1 String password2 = inputPassword2.getText().toString(); if (!Firstname.isEmpty() && !Surname.isEmpty() && !email.isEmpty() && !UserID.isEmpty()) { if (isEmailValid(email)) { if (!UserID.contains(" ")) { if (!countryString.equals("Select country of residence")) { if (EULAAccept.equals(true)) { if (isNetworkAvaliable(getApplicationContext())) { registerUser(Firstname, Surname, UserID, email, countryString); } else { Toast.makeText(getApplicationContext(), "Currently there is no network. Please try later.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please read and accept End User License Agreement.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please select a country of residence.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "In the User ID no spaces are allowed.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please enter a valid email address!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please enter your details!", Toast.LENGTH_SHORT) .show(); } } }); // Link to Login Screen btnLinkToLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(getApplicationContext(), LoginActivity.class); startActivity(i); finish(); } }); }
From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java
/** * @param fieldTable//from w ww . j a va 2 s .com * @param nameOfField * @param field */ private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal, final String fieldRemote) { if (mCurrentLocal == null || mCurrentSugar == null) return; // String fieldLocal = mCurrentLocal.get(nameOfField); // String fieldRemote = mCurrentSugar.get(nameOfField); TableRow row = new TableRow(this); final Spinner sourceSelect = new Spinner(this); sourceSelect.setBackgroundResource(R.drawable.black_underline); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources)); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sourceSelect.setAdapter(spinnerArrayAdapter); // Open the spinner when pressing any of the text fields OnClickListener spinnerOpener = new OnClickListener() { @Override public void onClick(View v) { sourceSelect.performClick(); } }; row.addView(sourceSelect); fieldTable.addView(row); row = new TableRow(this); TextView fieldName = new TextView(this); int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName()); fieldName.setText(this.getString(stringId)); fieldName.setTextSize(16); fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(), fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom()); fieldName.setOnClickListener(spinnerOpener); row.addView(fieldName); final TextView fieldValueLocal = new TextView(this); fieldValueLocal.setText(fieldLocal); fieldValueLocal.setTextSize(16); row.addView(fieldValueLocal); fieldValueLocal.setOnClickListener(spinnerOpener); fieldTable.addView(row); row = new TableRow(this); row.addView(new TextView(this));// add dummy control final TextView fieldValueRemote = new TextView(this); fieldValueRemote.setText(fieldRemote); fieldValueRemote.setTextSize(16); fieldValueRemote.setOnClickListener(spinnerOpener); row.addView(fieldValueRemote); sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); resolvedContacts[mPosResolved].set(nameOfField, fieldLocal); } else { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); resolvedContacts[mPosResolved].set(nameOfField, fieldRemote); } } @Override public void onNothingSelected(AdapterView<?> view) { } }); row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10); // Restore appropiate selections according to resolved contact if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) { sourceSelect.setSelection(0); } else { sourceSelect.setSelection(1); } fieldTable.addView(row); }
From source file:de.mprengemann.hwr.timetabel.TimetableActivity.java
private void initListNavigation() { Context context = getSupportActionBar().getThemedContext(); final ArrayAdapter<CharSequence> listAdapter = new ArrayAdapter<CharSequence>(context, R.layout.sherlock_spinner_item, application.getEventsDates()); listAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); if (listAdapter.isEmpty()) { getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } else {/*w w w.j av a 2 s . c om*/ getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); } getSupportActionBar().setListNavigationCallbacks(listAdapter, new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { subjectFragment.scrollTo(String.valueOf(listAdapter.getItem(itemPosition))); return true; } }); }
From source file:com.cssweb.android.base.DialogActivity.java
private void setAdapter(Spinner timeSpinner, String[] params) { ArrayAdapter<String> timeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); timeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Log.i("=================", ">>>>>>>>>>>>>>>>>>>>>>>>"+params); for (String param : params) { timeAdapter.add(param);/*from w w w. j av a 2 s . c om*/ } timeSpinner.setAdapter(timeAdapter); }
From source file:com.microsoft.identity.client.testapp.MainActivity.java
@Override public void bindSelectAccountSpinner(Spinner selectUser) { final ArrayAdapter<String> userAdapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item, new ArrayList<String>() { {//www . jav a 2s . c o m for (IAccount account : mApplication.getAccounts()) add(account.getUsername()); } }); userAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); selectUser.setAdapter(userAdapter); }