您好,我尝试在我的 java 代码中放入一个 Spinner,但它在 else if 语句中显示错误:
private EditText textName;
private EditText textContent;
private Spinner CategorySpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
configureButton1();
configureButton2();
textName = (EditText) findViewById(R.id.editTextName);
textContent = (EditText) findViewById(R.id.editContent);
CategorySpinner = (Spinner) findViewById(R.id.editCategorySpinner);
}
private void configureButton1() {
Button del = (Button)findViewById(R.id.btNewText);
del.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), StartActivity.class);
v.getContext().startActivity(myIntent);
}
});
}
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);
}
}
}
});
}
它在 CategorySpinner.getText() 中显示一个错误。我希望你能帮助我。我已经尝试了很多,但没有找到解决方案。