Remove text from spinner

岁酱吖の 提交于 2019-12-29 09:25:31

问题


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

It is EditText followed by Spinner.


Now I'm using custom style as follows

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.


回答1:


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.




回答2:


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.

Please go through below link.

https://github.com/lorensiuswlt/NewQuickAction3D




回答3:


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



来源:https://stackoverflow.com/questions/15479579/remove-text-from-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!