Remove text from spinner

2019-03-02 15:30发布

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.

3条回答
女痞
2楼-- · 2019-03-02 16:23

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.

查看更多
ら.Afraid
3楼-- · 2019-03-02 16:27

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

查看更多
乱世女痞
4楼-- · 2019-03-02 16:35

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

查看更多
登录 后发表回答