I have to know the click event from the spinner in the Activity. The OnClick Method of the MultiSelectionSpinner Class gets called, but I have no idea how to create a callback method for the Activity. Following is the Spinner Class and the Activity.
public class MultiSelectionSpinner extends Spinner implements
OnMultiChoiceClickListener {
String[] _items = null;
boolean[] mSelection = null;
ArrayAdapter<String> simple_adapter;
public MultiSelectionSpinner(Context context) {
super(context);
simple_adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item);
super.setAdapter(simple_adapter);
}
public MultiSelectionSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
simple_adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item);
super.setAdapter(simple_adapter);
}
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (mSelection != null && which < mSelection.length) {
mSelection[which] = isChecked;
simple_adapter.clear();
simple_adapter.add(buildSelectedItemString());
} else {
throw new IllegalArgumentException(
"Argument 'which' is out of bounds.");
}
}
public class mainActivity extends FragmentActivity
// Thats the spinner
MultiSelectionSpinner spinner;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Here I load the spinner with the Names
spinner = (MultiSelectionSpinner) findViewById(R.id.spinner);
spinner.setItems(Names);