Android Open Source - downtown Multi Spinner From Project Back to project page downtown .
License The source code is released under:
GNU General Public License
If you think the Android project downtown listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package org.dklisiaris.downtown.widgets;
/ * f r o m w w w . j a v a 2 s . c o m * /
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MultiSpinner extends Spinner implements OnMultiChoiceClickListener, OnCancelListener{
private List<String> items;
private boolean [] selected;
private String defaultText;
private MultiSpinnerListener listener;
private ArrayAdapter<String> adapter;
public MultiSpinner(Context context) {
super (context);
}
public MultiSpinner(Context arg0, AttributeSet arg1) {
super (arg0, arg1);
}
public MultiSpinner(Context arg0, AttributeSet arg1, int arg2) {
super (arg0, arg1, arg2);
}
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (which==0 && isChecked){
selected[0] = true;
for (int i=1;i<selected.length;i++){
selected[i] = false;
((AlertDialog) dialog).getListView().setItemChecked(i, false);
}
}
else if (which==0 && !isChecked){
selected[0] = true;
((AlertDialog) dialog).getListView().setItemChecked(0, false);
}
else if (which!=0 && isChecked){
selected[0] = false;
((AlertDialog) dialog).getListView().setItemChecked(0, false);
selected[which] = true;
}
else {
selected[which] = false;
boolean othersSelected = false;
for (int i=1;i<selected.length;i++){
if (selected[i] == true){
othersSelected = true;
break ;
}
}
if (!othersSelected){
selected[0] = true;
((AlertDialog) dialog).getListView().setItemChecked(0, true);
}
}
//adapter.notifyDataSetChanged();
}
@Override
public void onCancel(DialogInterface dialog) {
// refresh text on spinner
StringBuffer spinnerBuffer = new StringBuffer();
boolean someUnselected = false;
for (int i = 0; i < items.size(); i++) {
if (selected[i] == true) {
spinnerBuffer.append(items.get(i));
spinnerBuffer.append(", " );
} else {
someUnselected = true;
}
}
String spinnerText;
if (someUnselected) {
spinnerText = spinnerBuffer.toString();
if (spinnerText.length() > 2)
spinnerText = spinnerText.substring(0, spinnerText.length() - 2);
} else {
spinnerText = defaultText;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_spinner_item,
new String[] { spinnerText });
setAdapter(adapter);
listener.onItemsSelected(selected);
}
@Override
public boolean performClick() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMultiChoiceItems(
items.toArray(new CharSequence[items.size()]), selected, this );
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setOnCancelListener(this );
builder.show();
return true;
}
public void setItems(List<String> items, String allText,
MultiSpinnerListener listener) {
this.items = items;
this.defaultText = allText;
this.listener = listener;
// only zero position (all) is selected by default
selected = new boolean [items.size()];
for (int i = 0; i < selected.length; i++){
if (i==0)selected[i] = true;
else selected[i] = false;
}
// all text on the spinner
adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_spinner_item, new String[] { allText });
setAdapter(adapter);
}
public boolean [] getSelected() {
return selected;
}
public void setSelected(boolean [] selected) {
this.selected = selected;
}
public interface MultiSpinnerListener {
public void onItemsSelected(boolean [] selected);
}
}
Java Source Code List com.google.maps.android.BuildConfig.java com.google.maps.android.BuildConfig.java com.google.maps.android.MarkerManager.java com.google.maps.android.MathUtil.java com.google.maps.android.PolyUtil.java com.google.maps.android.SphericalUtil.java com.google.maps.android.clustering.ClusterItem.java com.google.maps.android.clustering.ClusterManager.java com.google.maps.android.clustering.Cluster.java com.google.maps.android.clustering.algo.Algorithm.java com.google.maps.android.clustering.algo.GridBasedAlgorithm.java com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm.java com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.java com.google.maps.android.clustering.algo.StaticCluster.java com.google.maps.android.clustering.view.ClusterRenderer.java com.google.maps.android.clustering.view.DefaultClusterRenderer.java com.google.maps.android.geometry.Bounds.java com.google.maps.android.geometry.Point.java com.google.maps.android.projection.Point.java com.google.maps.android.projection.SphericalMercatorProjection.java com.google.maps.android.quadtree.PointQuadTree.java com.google.maps.android.ui.BubbleIconFactory.java com.google.maps.android.ui.IconGenerator.java com.google.maps.android.ui.RotationLayout.java com.google.maps.android.ui.SquareTextView.java com.sothree.slidinguppanel.SlidingUpPanelLayout.java com.sothree.slidinguppanel.library.BuildConfig.java com.sothree.slidinguppanel.library.BuildConfig.java org.dklisiaris.downtown.Addresses.java org.dklisiaris.downtown.BuildConfig.java org.dklisiaris.downtown.FavsActivity.java org.dklisiaris.downtown.GlobalData.java org.dklisiaris.downtown.Intro.java org.dklisiaris.downtown.MainActivity.java org.dklisiaris.downtown.Manifest.java org.dklisiaris.downtown.MapActivity.java org.dklisiaris.downtown.MoreActivity.java org.dklisiaris.downtown.Products.java org.dklisiaris.downtown.SearchActivity.java org.dklisiaris.downtown.Search.java org.dklisiaris.downtown.SingleListItem.java org.dklisiaris.downtown.Subcategories.java org.dklisiaris.downtown.SubcatsAndFilters.java org.dklisiaris.downtown.Tabs.java org.dklisiaris.downtown.TestActivity.java org.dklisiaris.downtown.WebViewActivity.java org.dklisiaris.downtown.Websites.java org.dklisiaris.downtown.actionbar.ActionBar.java org.dklisiaris.downtown.actionbar.ScrollingTextView.java org.dklisiaris.downtown.adapters.AddressFilterAdapter.java org.dklisiaris.downtown.adapters.CustomAdapter.java org.dklisiaris.downtown.adapters.CustomStringAdapter.java org.dklisiaris.downtown.adapters.CustomSuggestionsAdapter.java org.dklisiaris.downtown.adapters.MultiSelectionAdapter.java org.dklisiaris.downtown.adapters.SubcatsAdapter.java org.dklisiaris.downtown.db.Banner.java org.dklisiaris.downtown.db.Category.java org.dklisiaris.downtown.db.Company.java org.dklisiaris.downtown.db.DBHandler.java org.dklisiaris.downtown.db.DBInterface.java org.dklisiaris.downtown.db.Image.java org.dklisiaris.downtown.db.InitData.java org.dklisiaris.downtown.db.Keyword.java org.dklisiaris.downtown.db.Mapping.java org.dklisiaris.downtown.db.Product.java org.dklisiaris.downtown.db.QueryBuilder.java org.dklisiaris.downtown.downloader.DownloadTask.java org.dklisiaris.downtown.downloader.NotificationHelper.java org.dklisiaris.downtown.helper.AccessAssets.java org.dklisiaris.downtown.helper.AlertDialogManager.java org.dklisiaris.downtown.helper.ConnectionDetector.java org.dklisiaris.downtown.helper.FileCache.java org.dklisiaris.downtown.helper.ImageLoader.java org.dklisiaris.downtown.helper.InfoHelper.java org.dklisiaris.downtown.helper.KeyboardUtil.java org.dklisiaris.downtown.helper.MemoryCache.java org.dklisiaris.downtown.helper.ShareHelper.java org.dklisiaris.downtown.helper.UpdateConfirmDialog.java org.dklisiaris.downtown.helper.UpdateHelper.java org.dklisiaris.downtown.helper.Utils.java org.dklisiaris.downtown.helper.XMLParser.java org.dklisiaris.downtown.maps.AbstractMapActivity.java org.dklisiaris.downtown.maps.CompanyMarker.java org.dklisiaris.downtown.maps.DirectionsInfo.java org.dklisiaris.downtown.maps.GMapV2Direction.java org.dklisiaris.downtown.maps.Nearby.java org.dklisiaris.downtown.maps.PopupAdapter.java org.dklisiaris.downtown.providers.KeywordContract.java org.dklisiaris.downtown.providers.KeywordProvider.java org.dklisiaris.downtown.widgets.AspectRatioImageView.java org.dklisiaris.downtown.widgets.CheckableRelativeLayout.java org.dklisiaris.downtown.widgets.CustomScrollView.java org.dklisiaris.downtown.widgets.FlipAnimator.java org.dklisiaris.downtown.widgets.InertCheckBox.java org.dklisiaris.downtown.widgets.MultiSpinner.java