0

I have a spinner in my activity and i want that it open the select menu as soon as the activity starts

This is my layout excerpt that the Spinner appears

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:background="#fff"
    android:layout_weight="5">

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:prompt="@string/app_name"
        android:gravity="center_vertical"/>

</LinearLayout>

And this is my class that should open the Menu

Spinner spn = (Spinner) findViewById(R.id.spinner);

spn.setFocusable(true);
spn.setFocusableInTouchMode(true);

spn.requestFocus();
JFPicard
  • 5,029
  • 3
  • 19
  • 43
  • Have you tried `spn`.[performClick()](http://developer.android.com/reference/android/widget/Spinner.html#performClick())? – codeMagic Apr 02 '15 at 17:29
  • I tried but still nothing is happen , Moreover , a error ocurred , i do not know why this is happening , but i found other way for the same effect , thanks for the help. – Gabriel Santos Apr 02 '15 at 17:55
  • Ok. You should post and accept your solution – codeMagic Apr 02 '15 at 17:57
  • Indeed I gave up of set focus on the Spinner , Then my "solution " do not answer my question , would be useless for future readers . – Gabriel Santos Apr 02 '15 at 18:00

1 Answers1

0

Replace Your above code with

 spn = (Spinner) findViewById(R.id.spinner);
 ArrayAdapter myadapter = ArrayAdapter.createFromResource(this,
 R.array.days, android.R.layout.simple_spinner_item);
 myadapter.setDropDownViewResource(
        android.R.layout.simple_spinner_dropdown_item);
 spn.setAdapter(myadapter);
  // Open the Spinner...
   spn.performClick();

Also define following array in strings.xml

<string-array name="days">
    <item >Sunday</item>
    <item >Monday</item>
    <item >Tuesday</item>
</string-array>

Above code is working for me it will work for you also.

Jaykishan Sewak
  • 822
  • 6
  • 13