0

For spinner how to set tittle ,i tried with 'prompt' in both xml and activity file ,it is showing as tittle for dropdown list after clicking on spinner but i want to give tittle for spinner how to do it,help me.

    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setPrompt(getResources().getString(R.string.hello_world));
  • you want the spinner button to have title? – Chethan Shetty Dec 24 '13 at 07:02
  • Check this : http://stackoverflow.com/a/3427058/1405983 – Hardik Joshi Dec 24 '13 at 07:03
  • @Prince hey i already seen just for tittle that much code??give me any short answer,if it is final answer i will stop using spinner. –  Dec 24 '13 at 07:06
  • Here is the perfect solution and it's working in my case.[http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one](http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one) – M D Dec 24 '13 at 08:23

3 Answers3

0

Try this :

spinner.setPrompt("Select Things");

Virag Brahme
  • 2,062
  • 1
  • 20
  • 32
0

I ended up using a Button instead. While a Button is not a Spinner, the behavior is easy to customize.

First create the Adapter as usual:

String[] items = new String[] {"One", "Two", "Three"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_dropdown_item, items);

Note that I am using the simple_spinner_dropdown_item as the layout id. This will help create a better look when creating the alert dialog.

In the onClick handler for my Button I have:

public void onClick(View w) {
  new AlertDialog.Builder(this)
  .setTitle("the prompt")
  .setAdapter(adapter, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {

      // TODO: user specific action

      dialog.dismiss();
    }
  }).create().show();
}

And that's it!

dipali
  • 10,966
  • 5
  • 25
  • 51
0

use that

 <Spinner
              android:id="@+id/spinner3"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
               android:entries="@array/gender"
            android:prompt="@string/Gender_prompt1" 
               />

and string.xml

<string name="Gender_prompt1">Choose a Gender</string>
The Ray of Hope
  • 738
  • 1
  • 6
  • 16