我的微调器有问题。我已经设置了 ArrayAdapter 并设置了 OnItemSelected 侦听器。但在 onClick 方法中,它在 els-if 语句中显示错误错误。
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.category_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
categorySpinner = (Spinner) findViewById(R.id.editCategorySpinner);
categorySpinner.setAdapter(adapter);
categorySpinner.setOnItemSelectedListener(this);
}
private void configureButton2() {
Button save = (Button) findViewById(R.id.btSave);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (textName.getText().length() == 0) {
textName.requestFocus();
return;
} else if (textContent.getText().length() == 0) {
textContent.requestFocus();
return;
} else if (categorySpinner.**getText**().length() == 0) {
CategorySpinner.requestFocus();
return;
} else {
//next Step: get the mood
Intent myIntent = new Intent(v.getContext(), Activity2.class);
myIntent.putExtra("textName", textName.getText().toString());
myIntent.putExtra("textContent", textContent.**getText**().toString());
myIntent.putExtra("CategorySpinner", CategorySpinner.**getText()**.toString());
v.getContext().startActivity(myIntent);
}
}
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
String selected = parent.getItemAtPosition(pos).toString();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
我在 else-if 语句中尝试了这个:
} else if (((CharSequence) docuCategory.getTag()).length() == 0) {
docuCategory.requestFocus();
return;
这没有显示任何错误,但模拟器“不幸停止”
希望您能够帮助我。