Spinner invitation not showing

enter image description here I have a Spinner (drop-down list of professions) in which I have a list of professions. I want to show the default value as "Choose a profession." In my xml, I type android: prompt = "Choose a profession" but nothing appears. I need the "Select Profession" to appear in the place where I marked it as red

Spinner.XML

<Spinner android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/sp_profession" android:layout_weight="1" style="@style/spinner" android:prompt="Select Profession" android:spinnerMode="dropdown" android:layout_margin="2dp"></Spinner> 

I did something like this, but get a null value at the prompt

 profession_array = getResources ().getStringArray (R.array.Profession); profession_str = new ArrayAdapter<String> (c, R.layout.textview_spinner, profession_array); prompt_text.setText ("Select Profession"); profession_str.setDropDownViewResource (android.R.layout.simple_dropdown_item_1line); 

R.layout.textview_spinner

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:id="@+id/prompt_text" android:layout_height="wrap_content" android:paddingBottom="10dp" android:paddingLeft="10dp" android:paddingTop="10dp" android:minHeight="1dp" android:gravity="center" android:textSize="20sp" android:textColor="@android:color/white" /> 
+7
android spinner
source share
4 answers

The tooltip is used to show the popup window title of the popup window not for the default text.

I think you are looking for setting the default value on the counter if you have not selected any value from the drop-down list. For this you need to use the NothingSelectedSpinnerAdapter, the link below is for more details:

stack overflow

+9
source share

Not the right way, but it works. Whatever you choose to show it as the first element in a String array like this

string.xml

  <string-array name="Profession"> <item>Please select the Profession</item> <item>Student</item> <item>Prof</item> <item>staff</item> <item>research student</item> 

in java code when reading ur from spinng object

 Spinner profession = (Spinner)findViewById(R.id.profession); String prof = String.valueOf(profession.getSelectedItem()); if(prof.equals("Please select the Profession")) { Toast.makeText(getApplicationContext(), "Please select the Profession", Toast.LENGTH_SHORT).show(); }else{ //Do your thing here.... } 
+4
source share

you must set the style ---> style = "@ android: style /Widget.Spinner" works for me. Hope this helps.

+2
source share

I had the same problem, and style="@android:style/Widget.Spinner" was the solution for me. just paste into Spinner tag without android: foreword

0
source share

All Articles