This is my code to populate the Spinner. It looks strange and ugly.
@Override
protected void onPostExecute(final List result) {
Sys
(SearchTopActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"test1", "test2"})
change this
android.R.layout.simple_spinner_dropdown_item to android.R.layout.simple_spinner_item
refer http://developer.android.com/resources/tutorials/views/hello-spinner.html
I think that happens because of the layout file you use. Try to use:
android.R.layout.simple_spinner_item
I had the same problem, I just wrote my own adapter by extending BaseAdapter and implementing SpinnerAdapter. Also I wrote my one item layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tvParticipantSpinnerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
And the spinner behave normally.
TRY THIS
@Override
protected void onPostExecute(final List<String> result) {
System.out.println("Result: " + result);
final String[] test = new String[] { "test1", "test2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, test);
countrySpinner.setAdapter(adapter);
}
and xml as::
<Spinner
android:id="@+id/countrySpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />