I'm using eneter framework to process communication in my android application; the problem is when I'm trying to populate a spinner, setting the adapter to the spinner cause an undefined exception
Here the code
public void populateSpinner(TypedResponseReceivedEventArgs<String> arg1){
List<String> list = new ArrayList<String>();
String listf = arg1.getResponseMessage();
//sendToDebug(listf);
StringTokenizer tokenizer = new StringTokenizer(listf,",");
while(tokenizer.hasMoreElements()){
list.add((String)tokenizer.nextElement());
}
//EditText text = (EditText)findViewById(R.id.number2EditText);
//text.setText(list.size());
//text.setText(listf);
Spinner forfait = (Spinner)findViewById(R.id.forfaitsSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
forfait.setAdapter(adapter);
}
Clearly each of your adapters need to adapt a different set of String s, so you need to create an ArrayAdapter for each Spinner . A single OnItemSelectedListener will work for the 3 Spinners (as long as you set them). You can call getId() on the AdapterView<?>
In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. To populate the spinner with a list of choices, you then need to specify a SpinnerAdapter in your Activity or Fragment source code.
A spinner adapter allows to define two different views: one that shows the data in the spinner itself and one that shows the data in the drop down list when the spinner is pressed.
Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.
you are passing this
in the following piece of code,
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,list);
Not sure in which block this code lies or which class, but ensure that this
refers to ActivityName.class
or the context
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With