i want the same as this link https://www.gorecess.com/ first spinner . multi selection spinner in android with checkbox .Show the spinner in dropdown. anyone know answer...
我要和这个链接https://www.gorecess.com/ first spinner一样。多选择旋转器在android与复选框。显示旋转器在下拉。谁知道答案……
3 个解决方案
#1
21
I have some links you can refer to make that type of view
我有一些链接,你可以参考,使那种类型的视图
follow this links
按照这个链接
Multi-Select Drop Down List in Android
Android中的多选择下拉列表
Spinner with multiple selection in Android
在安卓系统中有多个选择。
How to Customize Spinner in Android
如何在Android中自定义旋转器
This may help you
这可以帮助你
#2
6
<com.extra.MultiSelectionSpinner
android:id="@+id/input1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp" />
MultiSelectionSpinner spinner=(MultiSelectionSpinner)findViewById(R.id.input1);
List<String> list = new ArrayList<String>();
list.add("List1");
list.add("List2");
spinner.setItems(list);
For more info please click here
更多信息请点击这里。
#3
3
multi select spinner :
多选择微调控制项:
1- create a spinner in your own xml ,like this
1-在自己的xml中创建一个旋转器,如下所示
<Spinner
android:id="@+id/mySpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="1dp"/>
2-create a custom dapter for spinner like this :
2-创建一个用于spinner的自定义dapter:
public class AdapterTagSpinnerItem extends ArrayAdapter<TagListSimpleSearch>
{
private LayoutInflater mInflater;
private List<TagListSimpleSearch> listState;
public Spinner mySpinner = null;
public AdapterTagSpinnerItem(Context context, int resource, List<TagListSimpleSearch> objects, Spinner mySpinner)
{
super(context, resource, objects);
this.listState = objects;
this.mySpinner = mySpinner;
mInflater = LayoutInflater.from(context);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}
public View getCustomView(final int position, View convertView, ViewGroup parent)
{
String text = "";
final ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.spinner_item, null, false);
holder.mTextView = convertView.findViewById(R.id.tvSpinnerItem);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
/**
* check position , if position is zero we put space on top of list of spinner
*/
if ((position == 0))
text = oneSpace;
/**
* check position , if position is one we put cross mark before text to show that position used to be for clear all selected items on spinner
*/
else if ((position == 1))
text = " " + String.valueOf((char) crossMarkAroundBox) + " " + listState.get(position).getTagText();
/**
* check position , if position is two we put check mark before text to show that position used to be for select all items on spinner
*/
else if ((position == 2))
text = " " + String.valueOf((char) tikMarkAroundBox) + " " + listState.get(position).getTagText();
/**
* check position , if position is bigger than two we have to check that position is selected before or not and put check mark or dash before text
*/
else
{
if (listState.get(position).isSelected())
{
text = " " + String.valueOf((char) tikMark) + " " + listState.get(position).getTagText();
}
else
{
text = " " + String.valueOf(dash) + " " + listState.get(position).getTagText();
}
}
holder.mTextView.setText(text);
holder.mTextView.setTag(position);
holder.mTextView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
/**
* if you want open spinner after click on text for first time we have to open spinner programmatically
*/
mySpinner.performClick();
int getPosition = (Integer) v.getTag();
listState.get(getPosition).setSelected(!listState.get(getPosition).isSelected());
notifyDataSetChanged();
/**
* if clicked position is one
* that means you want clear all select item in list
*/
if (getPosition == 1)
{
clearList();
}
/**
* if clicked position is two
* that means you want select all item in list
*/
else if (getPosition == 2)
{
fillList();
}
}
});
return convertView;
}
/**
* clear all items in list
*/
public void clearList()
{
for (TagListSimpleSearch items : listState)
{
items.setSelected(false);
}
notifyDataSetChanged();
}
/**
* select all items in list
*/
public void fillList()
{
for (TagListSimpleSearch items : listState)
{
items.setSelected(true);
}
notifyDataSetChanged();
}
/**
* view holder
*/
private class ViewHolder
{
private TextView mTextView;
}
}
3- now you have to create object for adapter
3-现在你必须为适配器创建对象
public class TagListSimpleSearch {
private String TagId;
private String TagText;
private boolean selected;
public String getTagId() {
return TagId;
}
public void setTagId(String TagId) {
this.TagId = TagId;
}
public String getTagText() {
return TagText;
}
public void setTagText(String tagText) {
TagText = tagText;
}
public boolean isSelected()
{
return selected;
}
public void setSelected(boolean selected)
{
this.selected = selected;
}
}
4-fill spinner adapter in your activity
在您的活动中填充4个转轮适配器
public static String oneSpace =" ";
public static int tikMark =0X2714;
public static int crossMark =0X2715;
public static int tikMarkAroundBox =0X2611;
public static int crossMarkAroundBox =0X274E;
public static String dash ="-";
private Spinner mySpinner;
mySpinner= (Spinner) findViewById(R.id.mySpinner);
List<TagListSimpleSearch> tagsNames = new ArrayList<>();
TagListSimpleSearch tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("0");
tagSpecific.setTagText(oneSpace);
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("1");
tagSpecific.setTagText("select All Items");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("2");
tagSpecific.setTagText("remove All Items");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("0");
tagSpecific.setTagText("Item 0");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("1");
tagSpecific.setTagText("Item 1");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("2");
tagSpecific.setTagText("Item 2");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("3");
tagSpecific.setTagText("Item 3");
tagsNames.add(tagSpecific);
final AdapterTagSpinnerItem adapterTagSpinnerItem = new AdapterTagSpinnerItem(this, 0, tagsNames,mySpinner);
mySpinner.setAdapter(adapterTagSpinnerItem);
#1
21
I have some links you can refer to make that type of view
我有一些链接,你可以参考,使那种类型的视图
follow this links
按照这个链接
Multi-Select Drop Down List in Android
Android中的多选择下拉列表
Spinner with multiple selection in Android
在安卓系统中有多个选择。
How to Customize Spinner in Android
如何在Android中自定义旋转器
This may help you
这可以帮助你
#2
6
<com.extra.MultiSelectionSpinner
android:id="@+id/input1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp" />
MultiSelectionSpinner spinner=(MultiSelectionSpinner)findViewById(R.id.input1);
List<String> list = new ArrayList<String>();
list.add("List1");
list.add("List2");
spinner.setItems(list);
For more info please click here
更多信息请点击这里。
#3
3
multi select spinner :
多选择微调控制项:
1- create a spinner in your own xml ,like this
1-在自己的xml中创建一个旋转器,如下所示
<Spinner
android:id="@+id/mySpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="1dp"/>
2-create a custom dapter for spinner like this :
2-创建一个用于spinner的自定义dapter:
public class AdapterTagSpinnerItem extends ArrayAdapter<TagListSimpleSearch>
{
private LayoutInflater mInflater;
private List<TagListSimpleSearch> listState;
public Spinner mySpinner = null;
public AdapterTagSpinnerItem(Context context, int resource, List<TagListSimpleSearch> objects, Spinner mySpinner)
{
super(context, resource, objects);
this.listState = objects;
this.mySpinner = mySpinner;
mInflater = LayoutInflater.from(context);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}
public View getCustomView(final int position, View convertView, ViewGroup parent)
{
String text = "";
final ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.spinner_item, null, false);
holder.mTextView = convertView.findViewById(R.id.tvSpinnerItem);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
/**
* check position , if position is zero we put space on top of list of spinner
*/
if ((position == 0))
text = oneSpace;
/**
* check position , if position is one we put cross mark before text to show that position used to be for clear all selected items on spinner
*/
else if ((position == 1))
text = " " + String.valueOf((char) crossMarkAroundBox) + " " + listState.get(position).getTagText();
/**
* check position , if position is two we put check mark before text to show that position used to be for select all items on spinner
*/
else if ((position == 2))
text = " " + String.valueOf((char) tikMarkAroundBox) + " " + listState.get(position).getTagText();
/**
* check position , if position is bigger than two we have to check that position is selected before or not and put check mark or dash before text
*/
else
{
if (listState.get(position).isSelected())
{
text = " " + String.valueOf((char) tikMark) + " " + listState.get(position).getTagText();
}
else
{
text = " " + String.valueOf(dash) + " " + listState.get(position).getTagText();
}
}
holder.mTextView.setText(text);
holder.mTextView.setTag(position);
holder.mTextView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
/**
* if you want open spinner after click on text for first time we have to open spinner programmatically
*/
mySpinner.performClick();
int getPosition = (Integer) v.getTag();
listState.get(getPosition).setSelected(!listState.get(getPosition).isSelected());
notifyDataSetChanged();
/**
* if clicked position is one
* that means you want clear all select item in list
*/
if (getPosition == 1)
{
clearList();
}
/**
* if clicked position is two
* that means you want select all item in list
*/
else if (getPosition == 2)
{
fillList();
}
}
});
return convertView;
}
/**
* clear all items in list
*/
public void clearList()
{
for (TagListSimpleSearch items : listState)
{
items.setSelected(false);
}
notifyDataSetChanged();
}
/**
* select all items in list
*/
public void fillList()
{
for (TagListSimpleSearch items : listState)
{
items.setSelected(true);
}
notifyDataSetChanged();
}
/**
* view holder
*/
private class ViewHolder
{
private TextView mTextView;
}
}
3- now you have to create object for adapter
3-现在你必须为适配器创建对象
public class TagListSimpleSearch {
private String TagId;
private String TagText;
private boolean selected;
public String getTagId() {
return TagId;
}
public void setTagId(String TagId) {
this.TagId = TagId;
}
public String getTagText() {
return TagText;
}
public void setTagText(String tagText) {
TagText = tagText;
}
public boolean isSelected()
{
return selected;
}
public void setSelected(boolean selected)
{
this.selected = selected;
}
}
4-fill spinner adapter in your activity
在您的活动中填充4个转轮适配器
public static String oneSpace =" ";
public static int tikMark =0X2714;
public static int crossMark =0X2715;
public static int tikMarkAroundBox =0X2611;
public static int crossMarkAroundBox =0X274E;
public static String dash ="-";
private Spinner mySpinner;
mySpinner= (Spinner) findViewById(R.id.mySpinner);
List<TagListSimpleSearch> tagsNames = new ArrayList<>();
TagListSimpleSearch tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("0");
tagSpecific.setTagText(oneSpace);
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("1");
tagSpecific.setTagText("select All Items");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("2");
tagSpecific.setTagText("remove All Items");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("0");
tagSpecific.setTagText("Item 0");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("1");
tagSpecific.setTagText("Item 1");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("2");
tagSpecific.setTagText("Item 2");
tagsNames.add(tagSpecific);
tagSpecific=new TagListSimpleSearch();
tagSpecific.setTagId("3");
tagSpecific.setTagText("Item 3");
tagsNames.add(tagSpecific);
final AdapterTagSpinnerItem adapterTagSpinnerItem = new AdapterTagSpinnerItem(this, 0, tagsNames,mySpinner);
mySpinner.setAdapter(adapterTagSpinnerItem);