Skip to content Skip to sidebar Skip to footer

Android: Custom Spinner Layout

I am trying to make a fully custom spinner. I am running into difficulties with making the layout that pops up when you press on it. Here is my code for my adapter: ArrayAdapte

Solution 1:

row.xml to set up the layout on each row (in this case: one image and text each row):

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"><ImageViewandroid:id="@+id/icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/icon"/><TextViewandroid:id="@+id/weekofday"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>

Java:

publicclassAndroidCustomSpinnerextendsActivity {

 String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
   "Wednesday", "Thursday", "Friday", "Saturday"};

   /** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
       ArrayAdapter<String> adapter = newArrayAdapter<String>(this,
         R.layout.row, R.id.weekofday, DayOfWeek);
       mySpinner.setAdapter(adapter);
   }
}

Post a Comment for "Android: Custom Spinner Layout"