0

I tried to create a spinner and I want the view to look like this picture enter image description here

But why do I get a result like this enter image description here

Here is my code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="10dip" 
android:orientation="vertical" >    
<Spinner 
android:id="@+id/spinner" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:prompt="@+string/spinner_title" 
android:drawSelectorOnTop = "true"/> 
</LinearLayout>

And my activity

arrSpinner  = new Spinner(this);
List L = new ArrayList<String>();
L.add("Test 1");
L.add("Test 1");
arrAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,L);
arrSpinner.setPrompt("Pilih Jawaban");
addContentView(arrSpinner, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 
            LinearLayout.LayoutParams.WRAP_CONTENT));              
arrAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrSpinner.setAdapter(arrAdapter);
Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
Angripa
  • 159
  • 2
  • 4
  • 14

1 Answers1

1

I believe you're missing the android:spinnerMode attribute in your XML:

android:spinnerMode="dialog"

Hope that helps!

Edit: You'll need to actually use your XML spinner in the activity as well

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

...instead of:

arrSpinner  = new Spinner(this);
karllindmark
  • 6,031
  • 1
  • 26
  • 41