Android 2.3.3
I am having a Spinner in my xml file and I wish to set an ArrayList as a source. I am trying to instantiate the ArrayAdapter with the ArrayList, but i don't get the R.simple_spinner_adapter to select.
Here is the code :::
public class UnitConverter extends Activity{
Spinner spnUnit;
ArrayAdapter<String> ad;
ArrayList<String> alAngle = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.unitconverter);
spnUnit = (Spinner) findViewById(R.id.spinnerUnit);
ad = new ArrayAdapter<String>(this, android.R.simple_spinner_adapter, alAngle);
// Error at above line near android.R.simple_spinner_adapter
setDataToArrayLists();
}
The ans to ur question is u are not using adapter properly:-
android.R.simple_spinner_adapter should be android.R.layout.simple_spinner_item
Sample to this can be:-
Spinner spinner = (Spinner) findViewById(R.id.font_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.font_array,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
check using as above this is sample used in my code...!!!!
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