Even easier than setting up your own adapter counter, just use the button and style it as a spinner with
android:background="@android:drawable/btn_dropdown"
Then set the onClick button to open the single-element selection dialog box. Then you can do whatever you want with the button text.
This has been my preferred way of handling this for a while. Hope this helps someone.
EDIT: I recently communicated with this (and someone asked me to post an example some time ago). This strategy will look a little different if you use the Holo theme. However, if you use other themes such as Theme.Black, this will look the same.
To demonstrate this, I made a simple application that has both a regular Spinner and its own custom counter. I threw this in a GitHub repo , but here is what the action looks like:
package com.stevebergamini.spinnerbutton; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Spinner; public class MainActivity extends Activity { Spinner spinner1; Button button1; AlertDialog ad; String[] countries; int selected = -1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); spinner1 = (Spinner) findViewById(R.id.spinner1); button1 = (Button) findViewById(R.id.button1); countries = getResources().getStringArray(R.array.country_names);
SBerg413 Jan 31 '12 at 20:13 2012-01-31 20:13
source share