Aditi K
Aditi K

Reputation: 1554

How to show Spinner With Label (Static Text)?

I want to show spinner with static small label above it how it can be possible seen one of the popular app want to show same like it.

Here is my image, red marked one is the spinner with gray colored text above it which does not changes

I don't want to show android:prompt which shows default text inside spinner want to show exact above the spinner in same control

enter image description here

Upvotes: 13

Views: 20958

Answers (3)

Hamad
Hamad

Reputation: 5152

for this you will have to create custom spinner:

layout of spinner according to your need name it as custom_spinner:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tVStaticSmallLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="static text"
        android:textColor="#777777"
        android:textSize="22px" />

    <TextView
        android:id="@+id/tVMainText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tVStaticSmallLabel"
        android:layout_marginTop="5dip"
        android:text="your changing text" />
</RelativeLayout> 

in activity give this layout to the spinner:

Spinner mySpinner = (Spinner) findViewById(R.id.yourSpinner);
        mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner,
                spinnerValues));

Upvotes: 7

18446744073709551615
18446744073709551615

Reputation: 16832

I believe, it is a VerticalLayout with 2 items inside: one TextView and the other Spinner

Upvotes: 0

Paresh Mayani
Paresh Mayani

Reputation: 128428

That title is nothing but a TextView.

Upvotes: 1

Related Questions