Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Image to spinner in Android

I want to add an image to spinner I have tried like:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/myImage" />

But with this code the sign of down arrow on spinner becomes invisible please tell me how to solve that problem!! I want to do exactly Like in this image

enter image description here

like image 575
Arshad Ali Avatar asked Oct 31 '12 05:10

Arshad Ali


1 Answers

Create a row.xml in /res/layout/. To to setup the layout on each row.

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

and in Java file add this code as

 Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    R.layout.row, R.id.weekofday, YourArrayHere);
  mySpinner.setAdapter(adapter);
like image 167
Ram kiran Pachigolla Avatar answered Oct 06 '22 18:10

Ram kiran Pachigolla