没有选择选项微调器 [英] spinner with no select option
问题描述
我试图创建一个不应该有任何微调选择
但不是它,它应该是空白的,点击该项目可以选择了。
下面是我的code,请帮助。
urineGlucoseSpinner =(微调)view.findViewById(R.id.spnner_urine_glucose); ArrayList的<串GT; ugList =新的ArrayList<串GT;();
ugList.add(0,);
ugList.add(1.5);
ugList.add(5.5);
ugList.add(0.8);
ugList.add(9.5);
ugList.add(12.0); // ArrayAdapter<串GT; urineGlucoseAdapter =新ArrayAdapter<串GT;(getActivity(),android.R.layout.simple_spinner_item,ugList);
ArrayAdapter<串GT; urineGlucoseAdapter =新ArrayAdapter<串GT;(getActivity(),R.layout.custom_spinner_text,ugList);
urineGlucoseAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
urineGlucoseSpinner.setAdapter(urineGlucoseAdapter);
urineGlucoseSpinner.setSelection(0);
urineGlucoseSpinner.setOnItemSelectedListener(新OnUGItemSelected());
我可以看到两种方法可以做到这一点。
1)的空白行添加到您的数据在0位置,然后创建一个自定义的微调适配器和覆盖 getView
方法,并在其中使用如果
设置为0的位置视图GONE(因此在上市摆脱空行)。
2)另一种可能会在形式设置一个空的EditText,当它获得焦点弹出一个列表视图在一个对话框中你可能的选择。
I'm trying to create spinner which should not have any select
but instead of it, it should show Blank, after clicking that items can be selected.
Here is my code, please help.
urineGlucoseSpinner = (Spinner) view.findViewById(R.id.spnner_urine_glucose);
ArrayList<String> ugList = new ArrayList<String>();
ugList.add(0,"");
ugList.add("1.5");
ugList.add("5.5");
ugList.add("0.8");
ugList.add("9.5");
ugList.add("12.0");
//ArrayAdapter<String> urineGlucoseAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, ugList);
ArrayAdapter<String> urineGlucoseAdapter = new ArrayAdapter<String>(getActivity(),R.layout.custom_spinner_text, ugList);
urineGlucoseAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
urineGlucoseSpinner.setAdapter(urineGlucoseAdapter);
urineGlucoseSpinner.setSelection(0);
urineGlucoseSpinner.setOnItemSelectedListener(new OnUGItemSelected());
I can see two ways to do this.
1) Add the blank line to your data at position 0, and then create a custom spinner adapter and override the getView
method and in it use an if
to set the 0 position view to GONE (thus getting rid of the blank line in the listing).
2) An alternative might be setting an empty EditText in your form, and when it gains focus pop a listview in a dialog with your possible choices.
这篇关于没有选择选项微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!