2

Trying to make a spinner that pops up a new little screen the user can select their choice from, not just a drop down menu. I've been searching, all the "basic" spinner examples seem to accomplish the pop up spinner, but for the life of me I can't get it to do it on my machine.

What I have: http://developer.android.com/guide/topics/ui/controls/spinner.html

What I want: http://www.mkyong.com/android/android-spinner-drop-down-list-example/

I'd post the actual pics, but I don't have the reputation points to do so...

//@SuppressLint("ParserError")
public class Timer_appActivity extends Activity implements OnClickListener {
private static final String TAG = "TimerActivity";
//find view and assign to Java variable
EditText Hr;
EditText Min;
EditText Sec;
Button buttonGo;
Button buttonReset;
Spinner mySpinner;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);

    //find views
    mySpinner = (Spinner) findViewById(R.id.playlistSpinner);

    //get the names of the playlists on device
    List<String> list = new ArrayList<String>();
    String[] proj = {MediaStore.Audio.Playlists.NAME};
    Cursor myCursor = getContentResolver().query(Uri.parse("content://com.google.android.music.MusicContent/playlists"), proj, null, null, null);
    if (myCursor.getCount() > 0) {
        myCursor.moveToFirst();
        do {
            list.add(myCursor.getString(0));
        } while (myCursor.moveToNext());
    }
    myCursor.close();
    //define spinner adapter with nice spacing and playlist names
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, R.id.playlistNames, list);
    //populate adapter with playlist names
    mySpinner.setAdapter(adapter);

    //add listener to buttons
    //buttonGo.setOnClickListener(this);
    //buttonReset.setOnClickListener(this);

}
}

and row.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/linearlayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/playlistNames"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize = "25dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
/>
</LinearLayout>

and the xml for main2 looks like: (the bit for the spinner is the last entry)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tablelayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow
    android:layout_marginLeft="20dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="30dp" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView 
        android:id = "@+id/HoursLabel"
        android:text = "@string/stringHours"
        android:layout_column = "1"
        android:textSize="30dp"
        android:gravity = "center"
    />
    <TextView 
        android:id = "@+id/MinLabel"
        android:text = "@string/stringMin"
        android:layout_column = "3"
        android:textSize="30dp"
        android:gravity = "center"
    />
    <TextView 
        android:id = "@+id/SecLabel"
        android:text = "@string/stringSec"
        android:layout_column = "5"
        android:textSize="30dp"
        android:gravity = "center"
    />
    <TextView 
        android:layout_width="15dp"
    />
</TableRow>

<TableRow
    android:layout_marginLeft="20dp"
    android:layout_marginRight="15dp" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText 
        android:id ="@+id/HoursNum"
        android:hint = "@string/NoNumHrs"
        android:gravity = "center_horizontal"
        android:textSize="50dp"
        android:inputType="numberDecimal"
        android:layout_column = "1"
    />
    <TextView 
        android:id = "@+id/colon1"
        android:text = "@string/colon"
        android:textSize = "50dp"
    />
    <EditText 
        android:id ="@+id/MinNum"
        android:hint = "@string/NoNumMin"
        android:textSize="50dp"
        android:inputType="numberDecimal"
        android:gravity = "center_horizontal"
    />
    <TextView 
        android:id = "@+id/colon2"
        android:text = "@string/colon"
        android:textSize = "50dp"
    />
    <EditText 
        android:id ="@+id/SecNum"
        android:hint = "@string/NoNumSec"
        android:textSize="50dp"
        android:inputType="numberDecimal"
        android:gravity = "center_horizontal"
    />
</TableRow>
<TableRow
    android:layout_marginLeft="20dp"
    android:layout_marginRight="15dp" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Spinner
    android:id="@+id/playlistSpinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/selectplaylist"
    android:layout_marginTop="25dp"
    android:layout_column = "3"/>   
</TableRow>

Scott Decker
  • 4,229
  • 7
  • 24
  • 39
  • 1
    Do you need to [select a theme based on platform version](http://developer.android.com/guide/topics/ui/themes.html#SelectATheme)? Here's [an earlier question on this subject](http://stackoverflow.com/questions/9681648/how-to-use-holo-light-theme-and-fall-back-to-light-on-pre-honeycomb-devices). – Ken Y-N Aug 03 '12 at 03:46
  • 1
    @Ken, thanks for the tip...it definitely has to do with the theme chosen. I did a quick change in my Manifest file and, while the rest of it now looks terrible, the spinner acts as I want it to. I'll do some reading into how to customize themes...I think the soln lies there. Thanks! For those struggling...go into the AndroidManifest.xml and add the following: android:theme ="@android:style/Theme.Dialog" right after – Scott Decker Aug 04 '12 at 01:03

1 Answers1

4

Got it. Super simple.

Add the following to the attributes list of the spinner in the xml file.

android:spinnerMode="dialog"

other option is

android:spinnerMode="dropdown"

This works for level 11 and above, I believe...(maybe lower?)

So easy...urg

Scott Decker
  • 4,229
  • 7
  • 24
  • 39