Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

how to remove text that appears on a spinner control in android?

By default there is a text that comes up on a spinner control... .this text is the first value in the array that i have associated with the adapter for the spinner.

Upon selection this text changes to the value that i have selected.

I want to remove this text that appears on the spinner control. How do I go about it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To hide the selected text when the spinner is "closed", you have to define a custom adapter and a layout. To get an idea what this is all about I suggest that you read this blog entry.

So the steps you have to take would be:

  • Define a custom layout for the spinner when it is "closed". You can also define a custom layout for the dropdown mode of the spinner if you want to.
  • Implement a custom adapter. You have to override the getView() method and adapt it to your custom layout. In your case you would simply create and inflate the custom layout as you don't want to show any values you don't need to bind them to the view. If you also want a custom drowdown layout you also have to override the getDropDownView() method.
  • In your activity: Create a instance of you custom adapter, bind your data source (array or cursor) to it and bind the adapter to your spinner.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...