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.cse3310.phms.ui.activities.AddAppointmentActivity.java
@AfterViews void onSetupViews() { if (mSelectedDate != null) { appointmentTime = mSelectedDate.getTime(); }//from w w w.ja v a2 s . c o m // set spinner to get early reminder time ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.early_reminder_chose, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mReminderSpinner.setAdapter(adapter); mReminderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: earlyMillis = 0; break; case 1: earlyMillis = TimeUnit.MINUTES.toMillis(5); break; case 2: earlyMillis = TimeUnit.MINUTES.toMillis(10); break; case 3: earlyMillis = TimeUnit.MINUTES.toMillis(30); break; case 4: earlyMillis = TimeUnit.HOURS.toMillis(1); break; case 5: earlyMillis = TimeUnit.HOURS.toMillis(2); break; case 6: earlyMillis = TimeUnit.HOURS.toMillis(12); break; case 7: earlyMillis = TimeUnit.HOURS.toMillis(24); break; case 8: earlyMillis = TimeUnit.DAYS.toMillis(2); break; case 9: earlyMillis = TimeUnit.DAYS.toMillis(7); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mAppointmentView.setVisibility(View.GONE); mTimeButtonTextView.setText(MyDateFormatter.formatTime(mSelectedDate.getTime())); }
From source file:com.android.talkbacktests.testsession.PopupViewTest.java
@Override public View getView(final LayoutInflater inflater, ViewGroup container, Context context) { View view = inflater.inflate(R.layout.test_popup_view, container, false); final ArrayAdapter<String> windowTypeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, mWindowTypes); windowTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final ArrayAdapter<Integer> windowHeightAdapter = new ArrayAdapter<Integer>(context, android.R.layout.simple_spinner_item, sWindowHeight) { };//from w w w . j a v a 2 s . c o m windowHeightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final ArrayAdapter<Integer> listSizeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, sListSize); listSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWindowTypeSpinner = (Spinner) view.findViewById(R.id.window_type_spinner); mWindowTypeSpinner.setAdapter(windowTypeAdapter); mWindowTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) { if (pos == 0) { mModalCheckbox.setEnabled(false); } else { mModalCheckbox.setEnabled(true); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { mModalCheckbox.setEnabled(false); } }); mWindowHeightSpinner = (Spinner) view.findViewById(R.id.window_height_spinner); mWindowHeightSpinner.setAdapter(windowHeightAdapter); mListSizeSpinner = (Spinner) view.findViewById(R.id.list_size_spinner); mListSizeSpinner.setAdapter(listSizeAdapter); mListSizeSpinner.setSelection(4); // Set initial size to 10. The index is 4. mModalCheckbox = (CheckBox) view.findViewById(R.id.modal_checkbox); mModalCheckbox.setChecked(true); mDefaultInflaterCheckbox = (CheckBox) view.findViewById(R.id.inflater_checkbox); mDefaultInflaterCheckbox.setChecked(true); view.findViewById(R.id.button).setOnClickListener(this); return view; }
From source file:com.ducnd.recordvideo_sample.CaptureDemoFragment.java
private void initializeSpinners(final View rootView) { final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, RESOLUTION_NAMES); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); resolutionSp = (Spinner) rootView.findViewById(R.id.sp_resolution); resolutionSp.setAdapter(adapter);/* w w w.j a v a2 s. com*/ final ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, QUALITY_NAMES); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); qualitySp = (Spinner) rootView.findViewById(R.id.sp_quality); qualitySp.setAdapter(adapter2); }
From source file:com.microsoft.live.sample.ExplorerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.explorer);/*w w w .ja va2 s. c o m*/ LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication(); mConnectClient = app.getConnectClient(); mOperationListener = new OperationListener(); mResponseBodyText = (EditText) findViewById(R.id.responseBodyText); mPathText = (EditText) findViewById(R.id.pathText); mRequestBodyText = (EditText) findViewById(R.id.requestBodyText); mRequestBodyTextView = (TextView) findViewById(R.id.requestBodyTextView); final Spinner httpMethodSpinner = (Spinner) findViewById(R.id.httpMethodSpinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, HTTP_METHODS); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); httpMethodSpinner.setAdapter(adapter); httpMethodSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case GET: case DELETE: hideRequestBody(); break; case POST: case PUT: showRequestBody(); break; default: { makeToast("Unknown HTTP method selected: " + httpMethodSpinner.getSelectedItem().toString()); break; } } } @Override public void onNothingSelected(AdapterView<?> parent) { // Do nothing. } }); findViewById(R.id.submitButton).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String path = mPathText.getText().toString(); String bodyString = mRequestBodyText.getText().toString(); if (TextUtils.isEmpty(path)) { makeToast("Path must not be empty."); return; } int selectedPosition = httpMethodSpinner.getSelectedItemPosition(); boolean httpMethodRequiresBody = selectedPosition == POST || selectedPosition == PUT; if (httpMethodRequiresBody && TextUtils.isEmpty(bodyString)) { makeToast("Request body must not be empty."); return; } mProgressDialog = showProgressDialog("Loading. Please wait..."); switch (selectedPosition) { case GET: { mConnectClient.getAsync(path, mOperationListener); break; } case DELETE: { mConnectClient.deleteAsync(path, mOperationListener); break; } case POST: { mConnectClient.postAsync(path, bodyString, mOperationListener); break; } case PUT: { mConnectClient.putAsync(path, bodyString, mOperationListener); break; } default: { makeToast("Unknown HTTP method selected: " + httpMethodSpinner.getSelectedItem().toString()); break; } } } }); }
From source file:com.android.talkbacktests.testsession.StandardAndroidWidgetTest.java
@Override public View getView(final LayoutInflater inflater, ViewGroup container, final Context context) { View view = inflater.inflate(R.layout.test_standard_android_widget, container, false); final Button contDescButton = (Button) view.findViewById(R.id.test_standard_android_widget_button2); contDescButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w . java 2s. co m public void onClick(View view) { mCount++; contDescButton.setContentDescription(getString(R.string.toast_content_changed_template, mCount)); } }); Button toastButton = (Button) view.findViewById(R.id.test_standard_android_widget_button3); toastButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, R.string.toast_expand_button_clicked, Toast.LENGTH_LONG).show(); } }); ViewCompat.setAccessibilityDelegate(toastButton, new AccessibilityDelegateCompat() { public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat( AccessibilityNodeInfoCompat.ACTION_CLICK, getString(R.string.expand_button_action_label))); } }); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.city_array, android.R.layout.simple_spinner_item); Spinner spinner = (Spinner) view.findViewById(R.id.test_standard_android_widget_spinner); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); AutoCompleteTextView autocomplete = (AutoCompleteTextView) view .findViewById(R.id.test_standard_android_widget_autocomplete); autocomplete.setAdapter(adapter); mProgressBar = (ProgressBar) view.findViewById(R.id.test_standard_android_widget_progress_bar); mRunnable = new Runnable() { @Override public void run() { mProgressStatus += 5; mProgressBar.setProgress(mProgressStatus); if (mProgressStatus < 100) { mHandler.postDelayed(this, 1000); } } }; resetProgressBar(); View resetProgressBarButton = view.findViewById(R.id.test_standard_android_widget_reset_button); resetProgressBarButton.setOnClickListener(this); return view; }
From source file:com.fullmeadalchemist.mustwatch.ui.batch.form.AddIngredientDialog.java
@NonNull @Override/* w w w .ja v a2 s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { View view = LayoutInflater.from(getActivity()).inflate(R.layout.ingredient_dialog, null); viewModel = ViewModelProviders.of(this, viewModelFactory).get(BatchFormViewModel.class); String typeString = getArguments().getString(INGREDIENT_TYPE); Ingredient.IngredientType type; type = Ingredient.IngredientType.fromString(typeString); if (type == null) { type = Ingredient.IngredientType.SUGAR; } Timber.d("Got INGREDIENT_TYPE=%s", type); spinnerItems = new ArrayList<>(); LiveData<List<Ingredient>> ingredientsSpinnerObjects; int unitsSpinnerResource = 0; switch (type) { case YEAST: unitsSpinnerResource = R.array.mass_units_list; ingredientsSpinnerObjects = viewModel.getYeasts(); break; case NUTRIENT: unitsSpinnerResource = R.array.mass_units_list; ingredientsSpinnerObjects = viewModel.getNutrients(); break; case STABILIZER: unitsSpinnerResource = R.array.mass_units_list; ingredientsSpinnerObjects = viewModel.getStabilizers(); break; case SUGAR: default: unitsSpinnerResource = R.array.sugar_units_list; ingredientsSpinnerObjects = viewModel.getSugars(); break; } ingredientsSpinnerObjects.observe(this, ingredients -> { if (ingredients != null) { Timber.d("updating ingredients spinner with %d objects", ingredients.size()); spinnerItems = ingredients; List<String> stringifiedIngredients = new ArrayList<>(ingredients.size()); for (Ingredient ingredient : ingredients) { if (ingredient != null) { int resID = getResources().getIdentifier(ingredient.id, "string", this.getActivity().getPackageName()); stringifiedIngredients.add(getString(resID)); } else { Timber.e("Got a null ingredient from the database!?"); } } Spinner ingredientsSpinner = view.findViewById(R.id.ingredients_spinner); ArrayAdapter<String> ingredientsAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, stringifiedIngredients); ingredientsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ingredientsSpinner.setAdapter(ingredientsAdapter); } }); Spinner unitsSpinner = view.findViewById(R.id.quantity_unit_spinner); ArrayAdapter<CharSequence> unitsAdapter = ArrayAdapter.createFromResource(getActivity(), unitsSpinnerResource, android.R.layout.simple_spinner_item); unitsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); unitsSpinner.setAdapter(unitsAdapter); return new AlertDialog.Builder(getActivity()).setView(view) .setPositiveButton(android.R.string.ok, (dialog, which) -> { Spinner spinner = view.findViewById(R.id.ingredients_spinner); int selectedItemId = safeLongToInt(spinner.getSelectedItemId()); Ingredient selectedIngredient = spinnerItems.get(selectedItemId); Timber.d("Registered spinner number %d selected, corresponding to ingredient %s", selectedItemId, selectedIngredient.id); TextView qtyAmount = view.findViewById(R.id.quantity_amount); String qtyAmountValueText = qtyAmount.getText().toString(); float qtyValue = toFloat(qtyAmountValueText, 0.0f); //Spinner unitsSpinner = view.findViewById(R.id.quantity_unit_spinner); String selectedUnit = unitsSpinner.getSelectedItem().toString(); Timber.d("Ingredient selected: %s, %s %s", selectedIngredient.id, qtyValue, selectedUnit); Intent intent = new Intent(INGREDIENT_SET_EVENT); intent.putExtra(INGREDIENT, selectedIngredient.id); intent.putExtra(AMOUNT, qtyValue); intent.putExtra(UNIT, selectedUnit); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); }).setNegativeButton(android.R.string.cancel, null).create(); }
From source file:com.mrpoid.mrplist.ui.MrplistActivity.java
private void addScreenSizeNavigation() { screenSizeEnties = getResources().getStringArray(R.array.screensize_entries); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.screensize_entries, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(list, this); for (int i = 0; i < screenSizeEnties.length; ++i) { if (screenSizeEnties[i].equals(MrpScreen.getSizeTag())) { getSupportActionBar().setSelectedNavigationItem(i); break; }//from w ww . j ava 2s . c om } }
From source file:com.javielinux.fragments.SearchAdvancedFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = View.inflate(getActivity(), R.layout.search_advanced_fragment, null); btInfoNotifications = (Button) view.findViewById(R.id.bt_info_notifications); btInfoNotifications.setOnClickListener(new View.OnClickListener() { @Override//from w w w .j a va 2s . co m public void onClick(View v) { String file = "notifications_use.txt"; if (Locale.getDefault().getLanguage().equals("es")) { file = "notifications_use_es.txt"; } try { AlertDialog builder = DialogUtils.PersonalDialogBuilder.create(getActivity(), getActivity().getString(R.string.notifications), file); builder.show(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }); languages = (Spinner) view.findViewById(R.id.sp_languages); attitude = (Spinner) view.findViewById(R.id.sp_attitude); filter = (Spinner) view.findViewById(R.id.sp_filter); noRetweet = (CheckBox) view.findViewById(R.id.cb_no_retweet); source = (EditText) view.findViewById(R.id.et_source); ArrayAdapter<?> adapterLanguages = ArrayAdapter.createFromResource(getActivity(), R.array.languages, android.R.layout.simple_spinner_item); adapterLanguages.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); languages.setAdapter(adapterLanguages); ArrayAdapter<?> adapterAttitude = ArrayAdapter.createFromResource(getActivity(), R.array.attitude, android.R.layout.simple_spinner_item); adapterAttitude.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); attitude.setAdapter(adapterAttitude); ArrayAdapter<?> adapterFilter = ArrayAdapter.createFromResource(getActivity(), R.array.filter, android.R.layout.simple_spinner_item); adapterFilter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); filter.setAdapter(adapterFilter); notifications = (CheckBox) view.findViewById(R.id.cb_notifications); notificationsBar = (CheckBox) view.findViewById(R.id.cb_notifications_bar); notifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (searchIsNotification) { showFields(); } else { int max = Utils.MAX_NOTIFICATIONS; if (Utils.isLite(getActivity())) { max = Utils.MAX_NOTIFICATIONS_LITE; } int size = DataFramework.getInstance().getEntityList("search", "notifications=1").size() + 1; if (size <= max) { showFields(); } else { notifications.setChecked(false); if (Utils.isLite(getActivity())) { Utils.showMessage(getActivity(), getActivity().getString(R.string.max_notifications_lite)); } else { Utils.showMessage(getActivity(), getActivity().getString(R.string.max_notifications)); } } } } else { hideFields(); } } }); populateFields(); return view; }
From source file:com.e3h.usmcknowledge.activities.RankActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_rank); sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view); sideNavigationView.setMenuItems(R.menu.side_navigation_menu); sideNavigationView.setMenuClickCallback(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mLocations = getResources().getStringArray(R.array.rankenlisted); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.rankenlisted, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); // Activate Navigation Mode Tabs mActionBar = getSupportActionBar();/* w w w . j a v a 2 s . co m*/ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); //getSupportActionBar().setListNavigationCallbacks(list, ); // Locate ViewPager in activity_main.xml mPager = (ViewPager) findViewById(R.id.pager); // Activate Fragment Manager FragmentManager fm = getSupportFragmentManager(); // Capture ViewPager page swipes ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); // Find the ViewPager Position mActionBar.setSelectedNavigationItem(position); } }; mPager.setOnPageChangeListener(ViewPagerListener); // Locate the adapter class called ViewPagerAdapter.java ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm); // Set the View Pager Adapter into ViewPager mPager.setAdapter(viewpageradapter); // Capture tab button clicks ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { setmCounter(1); System.out.println("selected"); // Pass the position on tab click to ViewPager mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub System.out.println("unselected"); setmCounter(0); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub System.out.println("reselected"); } }; String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" }; for (int i = 0; i < menuItems.length; i++) { String item = menuItems[i]; tab = mActionBar.newTab().setText(item).setTabListener(tabListener); mActionBar.addTab(tab); } }
From source file:com.nadmm.airports.wx.WxMapFragmentBase.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflate(R.layout.wx_map_detail_view); if (mLabel != null && mLabel.length() > 0) { TextView tv = (TextView) v.findViewById(R.id.wx_map_label); tv.setText(mLabel);/*from w w w . j av a 2 s. com*/ tv.setVisibility(View.VISIBLE); } if (mHelpText != null && mHelpText.length() > 0) { TextView tv = (TextView) v.findViewById(R.id.help_text); tv.setText(mHelpText); tv.setVisibility(View.VISIBLE); } OnClickListener listener = new OnClickListener() { @Override public void onClick(View v) { if (mPendingRow == null) { mPendingRow = v; String code = getMapCode(v); requestWxMap(code); } } }; LinearLayout layout = (LinearLayout) v.findViewById(R.id.wx_map_layout); for (int i = 0; i < mWxMapCodes.length; ++i) { View row = addProgressRow(layout, mWxMapNames[i]); row.setTag(mWxMapCodes[i]); row.setOnClickListener(listener); row.setBackgroundResource(R.drawable.row_selector_middle); } if (mWxTypeCodes != null) { TextView tv = (TextView) v.findViewById(R.id.wx_map_type_label); tv.setVisibility(View.VISIBLE); layout = (LinearLayout) v.findViewById(R.id.wx_map_type_layout); layout.setVisibility(View.VISIBLE); mSpinner = (Spinner) v.findViewById(R.id.map_type); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, mWxTypeNames); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); mSpinner.setAdapter(adapter); } return v; }