1

I'm trying to style a spinner. What I currently have is this screen1

It is EditText followed by Spinner.


Now I'm using custom style as follows screen2

It also consists of an EditText followed by Spinner but Spinner is having some text(in this case "Other") on it which is Item name 1.

How do I remove that text i.e. selected item content should not be displayed on Spinner.
Spinner doesn't have any textSize attribute, otherwise I would have set it to 0.

I'm trying this from hours but no solution.
Any help appreciated.

GAMA
  • 5,958
  • 14
  • 79
  • 126
  • See this I think will helping you [link description here](http://stackoverflow.com/a/5989650/2059970) – AwadKab Mar 18 '13 at 15:02
  • I don't find ant particular way to remove the spinner text in the answer you suggested? – GAMA Mar 18 '13 at 15:08
  • You have to make a custom Spinner and use it see this link http://stackoverflow.com/questions/5988605/how-to-remove-text-that-appears-on-a-spinner-control-in-android?lq=1 – Rohit Mar 18 '13 at 15:11

3 Answers3

12

You have to implement your own adapter that sets the title to empty string. This will do:

private static class CustomAdapter<T> extends ArrayAdapter<String> {
        public CustomAdapter(Context context, int textViewResourceId, String[] objects) {
            super(context, textViewResourceId, objects);
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            TextView textView = (TextView) view.findViewById(android.R.id.text1);
            textView.setText("");
            return view;
        }       
}

If your spinner has an id R.id.spinner in your layout set the adapter like this:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
CustomAdapter<String> adapter = new CustomAdapter<String>(this, 
    android.R.layout.simple_spinner_dropdown_item, new String[] {"Entry 1", "Entry 2"});
spinner.setAdapter(adapter);

Of course the new String[] part would depend on what you want to display in your spinner or where the content of the spinner origins from.

Emanuel Moecklin
  • 28,488
  • 11
  • 69
  • 85
1

I think you should use Android QuickAction Widget.Link

Its an open source project in GitHub. Instead of Spinner you can use QucikAction. Its very looks attractive.

enter image description here

Please go through below link.

https://github.com/lorensiuswlt/NewQuickAction3D

Community
  • 1
  • 1
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
  • @EmanuelMoecklin its a very smart alternative of Spinner to overcome the Spinner Text issue. – Amit Gupta Mar 18 '13 at 15:24
  • It's a menu not a spinner. It doesn't reflect the platform's design, it looks "old" on a holo themed device while using the regular spinner will use the holo theme and so will fit the rest of the design elements. My approach is to use standard design elements wherever possible and use custom widgets only where no native one exists. Last but not least the question was how to remove the text in the spinner not how to implement a specific design pattern. – Emanuel Moecklin Mar 18 '13 at 15:31
  • I do agree with you. Its a custom widget and not native api. But some time we need to use custom component to achieve our requirement. Thanks. – Amit Gupta Mar 18 '13 at 15:34
0

Make the string empty with " ". (i.e. two qoutation marks, with a space in the middle.)

Eric Anthony
  • 927
  • 1
  • 8
  • 15
  • which String? I don't want that text ("others") on `Spinner`. – GAMA Mar 18 '13 at 14:58
  • @GAMA I assumed you were saying ` Item name 1` was a string with the text `"other"` which is were the spinner was getting it's text. In that case why remove it when you can just set it to a blank space. I see what you are saying now though, that isn't the case. – Eric Anthony Mar 18 '13 at 16:13