我正在尝试根据来自上一个活动的值初始化一个 String[] 数组。编译器说下面的代码有一个错误,它说“数组常量只能在初始化程序中使用”。没有其他选择可以做我想做的事吗?
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);
}
}
非常感谢你!!!我希望我们能找到解决办法!