android-spinner

Creating ArrayAdapter using xml resource and retrieving “id” or “value” fields using spinner

可紊 提交于 2019-12-22 07:03:43
问题 I am trying to create a spinner, the values of which I am populating from a resource xml, using ArrayAdapter. I also want to give the resource items some "id" or "value". How can i retrieve these values inside the onItemSelected() callback ? Here is the Java code. package com.waus.waus; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import

How can I invoke an action on the same selection of spinner value

拥有回忆 提交于 2019-12-22 05:23:11
问题 I select the value from spinner and when I select the same value again then no action is performed on the click. 回答1: Use this custom Spinner class... /** Spinner extension that calls onItemSelected even when the selection is the same as its previous value */ public class NDSpinner extends Spinner { public NDSpinner(Context context) { super(context); } public NDSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public NDSpinner(Context context, AttributeSet attrs, int

Get reference to a Spinner in ActionBar

。_饼干妹妹 提交于 2019-12-22 00:29:27
问题 findViewById() works fine when you need to find something any UI element that is in your layout. However, using the second option of this answer How to add a Dropdown item on the action bar, I added a Spinner to my ActionBar . Now the problem I am facing is how to retrieve a reference to this Spinner so that I can change the font that it uses. How do I do that? My menu/sort_spinner looks like this: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/sort"

Expand/open a spinner on click of another item/widget?

蹲街弑〆低调 提交于 2019-12-21 09:02:11
问题 I am trying to expand a Spinner when user click on another Button. as example : I have a Spinner with values and a 'OK' button when user click on 'ok' buttton without selecting any value from spinner, Spinner expands itself. Is this possible to get a event to expand spinner without user interaction on spinner. 回答1: Just call Spinner.performClick() to expand Spinner without user interaction... final Spinner spinner = (Spinner) findViewById(R.id.spinner); Button okButton = (Button) findViewById

Catching an event when spinner drop down is dismissed

左心房为你撑大大i 提交于 2019-12-21 07:14:27
问题 I want to catch an event when spinner drop down is dismissed. We can catch it when the user clicks on any item in the onItemSelected(). But I want to catch even when user touches outside of the drop down area or back button as these too make it disappear. In these two causes when I observed log, it says "Attempted to finish an input event, but the input event receiver has already been disposed" I observed the source code, this is printed from the InputEventReceiver.java in the

Spinner like edittext

笑着哭i 提交于 2019-12-21 05:56:08
问题 I have a form with TextInputLayout+TextInputEditText and spinners. I want the spinner height wrap text but have large items in the dropdown. The problem is that the spinner's height depends on the dropdown items height (simple_spinner_dropdown_item). I set style="@style/Base.Widget.AppCompat.Spinner.Underlined" in order to add line below spinner. Any solution? 回答1: Spinner like edittext If you want spinner like edittext, it's like AutoCompleteTextView .You can custom your

How to remove default value in spinner android?

隐身守侯 提交于 2019-12-20 23:29:23
问题 I am fetching the values from Database using JSON and inserting them into spinner. This process is running successfully. But I am receiving a Spinner hint two times, when I click on spinner; how can I remove the first default value from spinner... This is snapshot :- hope you understand my problem : This is my code:- private class GetCategories extends AsyncTask<Void, Void, Void> { protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(Void... arg0) {

How to add a spinner next to a menu in the toolbar

我是研究僧i 提交于 2019-12-20 19:39:05
问题 I want my spinner to be next to my menu in the toolbar (to the left of the menu), but currently the spinner appear below the menu. Do i have to add it somehow inside the onCreateOptionsMenu(Menu menu) My Activity: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); Spinner

How to set spinnerMode in Android 2.2?

拈花ヽ惹草 提交于 2019-12-20 15:34:05
问题 Can I use android:spinnerMode xml attribute in Android 2.2? I need to get an inline dropdown anchored to the Spinner widget than getting in dialog window. 回答1: Jake Wharton, the author of ActionBarSherlock library, made possible to use IcsSpinner outside of action bar. Read through this discussion: https://groups.google.com/d/topic/actionbarsherlock/fL-JL6Mn7kg/discussion IcsSpinner allow to setup dropdown or dialog mode. 来源: https://stackoverflow.com/questions/11840636/how-to-set-spinnermode

How to set spinnerMode in Android 2.2?

半世苍凉 提交于 2019-12-20 15:33:36
问题 Can I use android:spinnerMode xml attribute in Android 2.2? I need to get an inline dropdown anchored to the Spinner widget than getting in dialog window. 回答1: Jake Wharton, the author of ActionBarSherlock library, made possible to use IcsSpinner outside of action bar. Read through this discussion: https://groups.google.com/d/topic/actionbarsherlock/fL-JL6Mn7kg/discussion IcsSpinner allow to setup dropdown or dialog mode. 来源: https://stackoverflow.com/questions/11840636/how-to-set-spinnermode