我这里有点问题..
我已创建表单,并且使用列表视图有年和月的数组。
我的条件是,如果未选择年份或月份,弹出窗口将告诉您重新填写表单。
问题是,if语句不正确。
如何实际调用列表视图中选择的值?
public class card extends Activity implements OnItemSelectedListener {
Spinner spinnerOsversions;
Spinner spinnerOsversions2;
Button btnCtlr;
private String[] Month = { "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"};
private String[] Year = { "2014", "2015", "2016", "2017", "2018", "2019","2020" , "2021", "2022", "2023", "2024","2025" };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.card);
spinnerOsversions = (Spinner) findViewById(R.id.osversions);
spinnerOsversions2 = (Spinner) findViewById(R.id.osversions2);
ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Month);
adapter_state
.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinnerOsversions.setAdapter(adapter_state);
spinnerOsversions.setOnItemSelectedListener(this);
ArrayAdapter<String> adapter_state2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Year);
adapter_state2
.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinnerOsversions2.setAdapter(adapter_state2);
spinnerOsversions2.setOnItemSelectedListener(this);
btnCtlr = (Button) findViewById(R.id.button1);
btnCtlr.setOnClickListener(new ButtonClickHandler());
}
public void onItemSelected1(AdapterView<?> parent, View view, int position,
long id) {
spinnerOsversions.setSelection(position);
String selState = (String) spinnerOsversions.getSelectedItem();
}
public void onItemSelected2(AdapterView<?> parent, View view, int position,
long id) {
spinnerOsversions2.setSelection(position);
String selState = (String) spinnerOsversions2.getSelectedItem();
}
public class ButtonClickHandler implements View.OnClickListener {
public void onClick(View view) {
if((spinnerOsversions2.getSelectedItem().toString() == null) || ((spinnerOsversions.getSelectedItem().toString() == null))){
AlertDialog.Builder builder2=new AlertDialog.Builder(card.this);
builder2.setMessage("Please fill in all the information.");
builder2.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intObj2 = new Intent(getApplicationContext(),card.class);
startActivity(intObj2);
}
});
AlertDialog dialog = builder2.create();
dialog.show();
}
else{
Intent intObj = new Intent(card.this,
tq.class);
startActivity(intObj);
}