An Android micro-library with grouped pickers that makes choosing easy
Let your android application users find selectable items conveniently. Create and bind hierarchical grouped lists to your ArrayAdapters for Pickers , MultiAutoCompleteTextViews and Search Filter Views
As illustrated above, You could display items in groups with Group Headers as the hierachical parent for the selectable content.In addition to displaying array of (grouped) items vertically under each group, one could choose to show the same content using N columns layout by passing n as optional parameter to MultiSelectOptionsArrayAdapter constructor.
//MultiSelectOptionsArrayAdapter(Selection.SelectableListener listener, List collection, int columnsCount)
new MultiSelectOptionsArrayAdapter(listener, collection, columnsCount)
Simple example code that is used in this demo
mFavouritiesCollection = new ArrayList();
Selection.SelectableGroup flyGroup = new Selection.SelectableGroup("WE FLY");
List flyCollection = new ArrayList();
flyCollection.add(new Selection.SelectableItem("Pigeon", 11));
flyCollection.add(new Selection.SelectableItem("Parrot", 12));
flyGroup.addSelectableList(flyCollection);
mFavouritiesCollection.add(flyGroup);
Selection.SelectableGroup swimGroup = new Selection.SelectableGroup("WE SWIM");
List swimCollection = new ArrayList();
swimCollection.add(new Selection.SelectableItem("Gold Fish", 21));
swimCollection.add(new Selection.SelectableItem("Dolphin", 22));
swimGroup.addSelectableList(swimCollection);
mFavouritiesCollection.add(swimGroup);
selectOptionsAdapter = new MultiSelectOptionsArrayAdapter(this, mFavouritiesCollection);
If you are planning to use this library you are mostly likely going to use it with dynamic data array that is coming from a data store or a external WebAPI. We have built this for this exact purpose
You could be using HTTP libraries like Volley or Retrofit,
// JSON serialization structure for the deserialized object respresentation in the Hello Me Example
[{
"title": "WE FLY",
"collection": [{"name":"Pigeon", "id":11}, {"name":"Parrot", "id":12}]
},
{
"title": "WE SWIM",
"collection": [{"name":"Gold Fish", "id":21}, {"name":"Dolphin", "id":22}]
}]
You could be using JSON library like Gson or Jackson BUT, When you need to extend and use custom objects you could implement Selectable Interface All the object instances that are to be selectable (a.k.a clickable) should implement Selection.Selectable Interface
public class Profile
implements Serializable, Selection.Selectable {
@SerializedName("profile_type")
Selection.SelectedResult.IdType profileType;
@SerializedName("profile_ref_id")
int profileRefId;
@SerializedName("profile_title")
String title;
@SerializedName("img_path")
String profileIcon;
@Override
public int getId() {
return profileRefId;
}
@Override
public String getName() {
return title;
}
@Override
public String getImage() {
return profileIcon;
}
@Override
public void setSelected(boolean selected) {
}
@Override
public boolean isSelected() {
return false;
}
}
Construct/Build collection array from array of Selectable objects (refer Hello Me Example above)
Implement Selection.SelectableListener and pass in listner and collection array to MultiSelectOptionsArrayAdapter adapter
//MultiSelectOptionsArrayAdapter(Selection.SelectableListener listener, List collection, int columnsCount)
new MultiSelectOptionsArrayAdapter(listener, collection, columnsCount)
-If you have suggestion(s) on how the API for this library could be improved, Plz create a issue
-If you could like contribute to this library, you are welcome to do a pull request
Open sourced with MIT license