【问题标题】:Multi selection in spinner微调器中的多选
【发布时间】:2016-05-04 11:03:04
【问题描述】:

我创建了 2 个微调器,我需要让用户能够从每个微调器中选择多个东西。我设法通过 android.R.layout.simple_list_item_multiple_choice 添加复选框。现在我设法得到了我想要的一切,但问题是如何让用户选择多个已经有复选框的东西,但是当用户点击某个项目时,它会立即关闭微调器并在该项目上保持选中状态。

这是我得到并且想要的设计,但问题在于选择。

http://pokit.org/get/?1c872c5becdeb79b792617fc870f1da4.jpg 这是选择: http://pokit.org/get/?e892ee2f941ab3f98b8ee51e6f9e8fc6.jpg

这是该微调器的当前代码:

 public void onViewCreated(View view, Bundle savedInstanceState) {
    Spinner placesspinner=(Spinner)getActivity().findViewById(R.id.spinner_locations);
    Spinner catspinner=(Spinner)getActivity().findViewById(R.id.spinner_category);
    ArrayAdapter<String> adp1=new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_multiple_choice,places);
    placesspinner.setAdapter(adp1);
    catspinner.setAdapter(adp1);
    // Setup any handles to view objects here
    // EditText etFoo = (EditText) view.findViewById(R.id.etFoo);
}

【问题讨论】:

标签: java android android-layout android-studio android-spinner


【解决方案1】:

默认情况下,Spinner 控件处于单选模式。

您所做的只是更改了布局以显示带有复选框的微调器项目。这并不意味着您正在显示一个多选择微调器控件。

您可以参考下面提到的任何示例来实现多选微调器。

multi-select-drop-down-list

android-spinner-like-ui-for-selecting-multiple-options

spinner-with-multiple-selectiondescription here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多