How to use Android Spinner with multiple choice in Fragment of Navigation drawer activity
如何创建允许选择多个项目的微调器,即带有复选框的微调器?同时我需要在导航抽屉活动的片段中使用这个多选微调器。
任何人都可以用合适的示例代码解决我的疑问。
提前谢谢你!!!
public Doctor() {
// Required empty public constructor
}
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { // Inflate the layout for this fragment getActivity().setTitle("Doctor"); View v = inflater.inflate(R.layout.fragment_doctor, container, false); String [] values = {"All Town","Paris","Kodambakkam","Nungambakkam","T.Nagar","Egmore"}; Spinner spinner = (Spinner) v.findViewById(R.id.town); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); spinner.setAdapter(adapter); String [] values1 = String [] values2 = return v; } |
}
我需要将 spinner2 更改为我们的多项选择微调器。我正在从 Fragment 扩展课程。所以不知道如何处理这个多选微调器
1 How do I create spinner which allows to choose multiple items, i.e spinner with check boxes?
尝试使用 multiselectionspinner。
https://stackoverflow.com/a/6022474/6616489
对于
multiple choice spinner inside the fragment of Navigation drawer
参考 https://stackoverflow.com/a/20017862/6616489
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
public class Doctor extends Fragment{
MultiSelectionSpinner spinner2; @Override String [] values = String [] values1 = String [] values2 = |
上面的代码是多选微调器(注:微调器2)
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
public class MultiSelectionSpinner extends Spinner implements OnMultiChoiceClickListener { String[] _items = null; boolean[] mSelection = null; ArrayAdapter<String> simple_adapter; public MultiSelectionSpinner(Context context) { simple_adapter = new ArrayAdapter<String>(context, public MultiSelectionSpinner(Context context, AttributeSet attrs) { simple_adapter = new ArrayAdapter<String>(context, public void onClick(DialogInterface dialog, int which, boolean isChecked) { simple_adapter.clear(); @Override @Override public void setItems(String[] items) { public void setItems(List<String> items) { public void setSelection(String[] selection) { public void setSelection(List<String> selection) { public void setSelection(int index) { public void setSelection(int[] selectedIndicies) { public List<String> getSelectedStrings() { public List<Integer> getSelectedIndicies() { private String buildSelectedItemString() { for (int i = 0; i < _items.length; ++i) { sb.append(_items[i]); public String getSelectedItemsAsString() { for (int i = 0; i < _items.length; ++i) { |
以上代码用于创建从 spinner2 调用的多选微调器。
请检查代码。如果有任何疑问,请在此处发表评论,让我尝试消除您的疑问。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/269037.html