0

I would like a customized spinner which comes up when I click a link button. So I don't want to see the spinner value or icon V at all. Just click and the spinner pops up.

So 1) Does android have a link button. Or how could I use Button with just button label showing and now border seamless?

2) How do I bring up the spinner from the link button?

3) How do I catch the selected spinner value?

Androider
  • 21,125
  • 36
  • 99
  • 158

1 Answers1

1
  1. No, Android does not have a dedicated link button, but buttons can be styled and themed so you can certainly make them look as links:

    Create custom button with <selector> to style different Button states (pressed/released).

    To make button transperent use:

    android:background="@null"
    
  2. Register a Button.onClickListener() so that when clicked a Dialog with a Spinner is opened:

     button.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             // Put code to show Dialog here
         }
     });
    
  3. Register spinner.onItemSelected() handler as shown in the above link.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Button btnChange = (Button)findViewById(R.id.btnChange); btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Spinner mySpinner = (Spinner) findViewById(R.id.sSpinner); mySpinner.showContextMenu(); } }); would not work for this? – Androider Feb 19 '11 at 09:57
  • No. Spinner is a widget so it most be placed inside a container: an Activity, a Dialog, etc.. Just follow the code in the example. You can create a custom SpinnerDialog with this code, to have a cleaner design. – Peter Knego Feb 19 '11 at 10:10
  • How would one close the dialog after selection. Also I put toast message in onItemSelected of spinner and noticed it always gets called once on itialization of the dialog, so how can I tell it a user made the selection? – Androider Feb 19 '11 at 15:45
  • Dialog is closed by calling `viewDialog.dismiss()`. – Peter Knego Feb 19 '11 at 17:12
  • This seems relevant for your phantom spinner clicks: http://stackoverflow.com/questions/2562248/android-how-to-keep-onitemselected-from-firing-off-on-a-newly-instantiated-spinn – Peter Knego Feb 19 '11 at 17:15
  • I would like to open Spinner with just a single click from activity. Dialog seems like two step open dialog and then open spinner? – Androider Feb 26 '11 at 09:28
  • http://stackoverflow.com/questions/2679804/possible-to-programmatically-open-a-spinner-in-android-app – Peter Knego Feb 26 '11 at 09:45