How to add cancel button to spinner dialog?

732 Views Asked by At

I have a spinner with its mode set to dialog:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner1"
            android:spinnerMode="dialog"
            android:dropDownWidth="match_parent"
            android:textAppearance="@style/TextAppearance.Medium"
            android:prompt="@string/label_selection" />

How can I a Cancel button to its dialog?

1

There are 1 best solutions below

0
On BEST ANSWER

The only way is to create your own custom spinner, like:

public class MySpinner extends Spinner implements OnClickListener {
   //blah-blah
}

Important things need to be implemented:

  1. protected onDraw() - which would actually draw your MySpinner + button
  2. protected void onMeasure(int widthSpec, int heightSpec) - defines size of your custom spinner

Here's a link to tutorial which covers basics of custom widgets