List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:com.asksven.betterbatterystats.RawStatsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.raw_stats);//from w w w . ja va2s . c om Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.label_raw_stats)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayUseLogoEnabled(false); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { doRefresh(); } }); // 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); spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); spinnerStat.setAdapter(spinnerStatAdapter); // setSelection MUST be called after setAdapter spinnerStat.setSelection(m_iStat); spinnerStat.setOnItemSelectedListener(this); TextView tvSince = (TextView) findViewById(R.id.TextViewSince); long sinceMs = SystemClock.elapsedRealtime(); if (sinceMs != -1) { String sinceText = DateUtils.formatDuration(sinceMs); tvSince.setText(sinceText); Log.i(TAG, "Since " + sinceText); } else { tvSince.setText("n/a "); Log.i(TAG, "Since: n/a "); } }
From source file:com.ayuget.redface.ui.fragment.TopicListFragment.java
protected void initializeToolbarTitle(Toolbar toolbar) { View spinnerContainer = LayoutInflater.from(getActivity()).inflate(R.layout.actionbar_spinner, toolbar, false);//from ww w .ja v a2 s .c o m ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); toolbar.addView(spinnerContainer, 0, lp); Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.actionbar_spinner); spinner.setAdapter(subcategoriesAdapter); // "Hack to avoid onItemSelected to be fired off on spinner instantiation spinner.setSelection(0, false); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> spinner, View view, int position, long itemId) { if (subcategoriesAdapter.getItemViewType(position) == SubcategoriesAdapter.TYPE_CATEGORY) { subcategory = null; // Reset subcategory filtering } else { subcategory = (Subcategory) subcategoriesAdapter.getItem(position); } loadTopics(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
From source file:org.leopub.mat.controller.PersonalInfoActivity.java
public void updateCategoryView() { int n = mInfoCategoryList.size(); String categories[] = new String[n]; for (int i = 0; i < n; i++) { categories[i] = mInfoCategoryList.get(i).getName(); }//w w w .j av a 2s .c o m ArrayAdapter<String> categoryAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, categories); Spinner spinner = (Spinner) findViewById(R.id.category_spinner); spinner.setAdapter(categoryAdapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mChosenCategory = mInfoCategoryList.get(position); GetPersonalInfoTask getTask = new GetPersonalInfoTask(); getTask.execute(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
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())); }/*ww w .ja va 2s . co m*/ }
From source file:com.fullmeadalchemist.mustwatch.ui.batch.form.AddIngredientDialog.java
@NonNull @Override/*from w w w. jav a2 s . c om*/ 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:org.leopub.mat.controller.ComposeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); getActionBar().setDisplayHomeAsUpEnabled(true); mUser = UserManager.getInstance().getCurrentUser(); mReceivers = ""; mMessageType = MessageType.Text; mStartTime = new DateTime(); mEndTime = new DateTime(); mInputDst = (EditText) findViewById(R.id.compose_dst); mInputStartTime = (EditText) findViewById(R.id.compose_start_time); mInputEndTime = (EditText) findViewById(R.id.compose_end_time); mInputPlace = (EditText) findViewById(R.id.compose_place); mInputText = (EditText) findViewById(R.id.compose_text); mInputDst.addTextChangedListener(new PrivateTextWatcher()); String[] types = { getString(R.string.message_type_text), getString(R.string.message_type_meeting), getString(R.string.message_type_task) }; Spinner spinner = (Spinner) findViewById(R.id.compose_type); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, types); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(arrayAdapter); spinner.setOnItemSelectedListener(new PrivateSpinnerListener()); TouchDateTimeListener touchDateTimeListener = new TouchDateTimeListener(); mInputStartTime.setText(mStartTime.toSimpleString()); mInputStartTime.setOnTouchListener(touchDateTimeListener); mInputEndTime.setText(mEndTime.toSimpleString()); mInputEndTime.setOnTouchListener(touchDateTimeListener); showSendProgress(false);/*from www . j a v a2 s.c om*/ mBroadcastManager = LocalBroadcastManager.getInstance(this); mBroadcastFilter = new IntentFilter(Configure.BROADCAST_MESSAGE); mBroadcastReceiver = new PrivateBroadcastReceiver(); }
From source file:com.micabyte.android.app.BaseFragment.java
@SuppressWarnings("ConstantConditions") protected Spinner setSpinner(int resId, int arrId) { final Spinner s = (Spinner) getView().findViewById(resId); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( getActivity().getApplicationContext(), arrId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(adapter); return s;/*from w w w. ja va 2 s .com*/ }
From source file:hku.fyp14017.blencode.content.bricks.BroadcastReceiverBrick.java
@Override public View getPrototypeView(Context context) { View prototypeView = View.inflate(context, hku.fyp14017.blencode.R.layout.brick_broadcast_receive, null); Spinner broadcastReceiverSpinner = (Spinner) prototypeView .findViewById(hku.fyp14017.blencode.R.id.brick_broadcast_receive_spinner); broadcastReceiverSpinner.setFocusableInTouchMode(false); broadcastReceiverSpinner.setFocusable(false); SpinnerAdapter broadcastReceiverSpinnerAdapter = MessageContainer.getMessageAdapter(context); broadcastReceiverSpinner.setAdapter(broadcastReceiverSpinnerAdapter); setSpinnerSelection(broadcastReceiverSpinner); return prototypeView; }
From source file:com.armtimes.dialogs.DialogSettings.java
private void initImageQualityControllers(final View view) { Spinner spinner = (Spinner) view.findViewById(R.id.spinnerImageQuality); ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_quality_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(getImageQuality(getActivity())); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from w w w .j a v a2 s . c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setImageQuality(getActivity(), position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
private void setupPatientSpinner() { String[] names = new String[pats.size() + 1]; names[0] = "Todos"; for (int i = 0; i < pats.size(); i++) { names[i + 1] = pats.get(i).name(); }//from w w w .j av a 2 s . c om ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.toolbar_spinner_item, names); adapter.setDropDownViewResource(R.layout.toolbar_spinner_item); Spinner spinner = (Spinner) findViewById(R.id.toolbar_spinner); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { selectedPatientIdx = i; onPatientUpdate(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }