I'm trying to initialize an array of String[] depending of the value that comes from the previous activity. The compiler says there is an error in the following code and it says "Array constants can only be used in initializers". Is there no alternative to do what I'm trying to do?
public class ZeroParameter extends Activity{
int option, model;
String[] models;
protected void onCreate(Bundle savedInstanceState)
{
Bundle b = getIntent().getExtras();
option = b.getInt("option");
switch(option)
{
case 1:
models={ "Mike" , "Charls" , "Jhon"}
case 2:
models={"Paul" , "Louis" };
}
super.onCreate(savedInstanceState);
setContentView(R.layout.zero_parameter);
final Spinner spinModel=(Spinner)findViewById(R.id.spinnerModel0);
spinModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View v, int position,long id)
{
model = spinModel.getSelectedItemPosition();
}
public void onNothingSelected(AdapterView<?> arg0)
{
}
});
ArrayAdapter<String> aa= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,models);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinModel.setAdapter(aa);
}
}
Thanks you very much!!! I hope we can find a solution!