im to populate spinner using arraylist , and that arraylist actully holds data from the file having android application data stored already for t=my application, im pasting the
Try to initialize your spinner adapter with array in constructor.
String[] wee = list2.toArray(new String[list2.size()]);
final String[] str={"Report 1","Report 2","Report 3","Report 4","Report 5"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, wee);
spinnerArrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
// Spinner spinYear = (Spinner)findViewById(R.id.spin);
spin.setAdapter(spinnerArrayAdapter);
private void setSpinner() {
spinner = (Spinner) findViewById(R.id.spinner_size);
Intent intent = getIntent();
ArrayList<String> sizes = null;
if (intent != null) {
// Receiving ArrayList in Another Activity where "sizeList" is the Key
sizes = intent.getStringArrayListExtra("SizeList");
}
if (sizes != null) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, sizes);
spinner.setAdapter(adapter);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
}
}
Call setSpinner() method from OnCreate() Method. You can directly pass ArrayList as a parameter, you don't need to convert into String[].