I wrote a custom implementation of MultiSpinner. It looks like a regular spinner, but instead of fluctuations, it has flags. The selected values ββare displayed on a counter separated by a comma. All values ββare checked by default. Try:
package cz.destil.settleup.gui; public class MultiSpinner extends Spinner implements OnMultiChoiceClickListener, OnCancelListener { private List<String> items; private boolean[] selected; private String defaultText; private MultiSpinnerListener listener; 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 (isChecked) selected[which] = true; else selected[which] = false; } @Override public void onCancel(DialogInterface dialog) {
You use it in XML as follows:
<cz.destil.settleup.gui.MultiSpinner android:id="@+id/multi_spinner" />
And you pass it the data in Java as follows:
MultiSpinner multiSpinner = (MultiSpinner) findViewById(R.id.multi_spinner); multiSpinner.setItems(items, getString(R.string.for_all), this);
You also need to implement a listener that will return the same array of length, with true or false, to map the selected to unselected.
public void onItemsSelected(boolean[] selected);
David VΓ‘vra May 16 '11 at 19:43 2011-05-16 19:43
source share