在我的源代码中,我有两个活动。在活动A.java中我有一个数组
private String[] typeName = new String[100];
我也开始了一项新活动
public void LoadCueCardSet(View view){
Intent loadCueCardPage = new Intent(this, LoadCueCardSet.class);
loadCueCardPage.putExtra("types", typeName);
startActivity(loadCueCardPage);
}
在第二项活动中,我有
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_cue_card_set);
// Array of choices
// Selection of the spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Application of the Array to the Spinner
Bundle extras = getIntent().getExtras();
String colors[] = extras.getStringArray("types"); // doesn't work
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
spinner.setAdapter(spinnerArrayAdapter);
我知道问题在于微调器,它与我传递的数组有关,但问题是它应该工作,因为我尝试使用在第二个活动中创建的实际数组。如果我不使用从另一个活动传递的数组,则下面的代码可以使用。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_cue_card_set);
// Array of choices
// Selection of the spinner
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Application of the Array to the Spinner
String colors[] = {"red"}; //works
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
spinner.setAdapter(spinnerArrayAdapter);