Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and 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 Reply

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...