我能够通过布局向Spinner显示提示。我希望在单击“提交”按钮后显示微调器字段,并显示提示。我正在使用 spinner_district.setSelection(1); 它显示值为1的数组但我想显示提示而不是任何微调器的值。
用于清算字段
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
功能
public void onClick(View v) {
switch (v.getId()) {
case R.id.send_school_registration_form:
if (isConnected()) {
String name = registerSchoolName.getText().toString();
String address = registerSchoolAddress.getText().toString();
String phone = registerSchoolPhone.getText().toString();
String email = registerSchoolEmail.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
String website = registerSchoolWebsite.getText().toString();
String estbdate = schoolEstDate.getText().toString();
String admissionOpen = schoolAdmissionStartDate.getText().toString();
String admissionEnd = schoolAdmissionEndDate.getText().toString();
district = null;
if (spinner_district != null && spinner_district.getSelectedItem() != null) {
district = (String) spinner_district.getSelectedItem();
}
country = null;
if (spinner_country != null && spinner_country.getSelectedItem() != null) {
country = (String) spinner_country.getSelectedItem();
}
institution = null;
if (spinner_institution != null && spinner_institution.getSelectedItem() != null) {
institution = (String) spinner_institution.getSelectedItem();
}
fee = registerSchoolFee.getText().toString();
level = null;
if (spinner_school_level != null && spinner_school_level.getSelectedItem() != null) {
level = (String) spinner_school_level.getSelectedItem();
}
if (addSchoolProgram1.getVisibility() == View.VISIBLE) {
fee1 = registerSchoolFee1.getText().toString();
level1 = null;
if (spinner_school_level1 != null && spinner_school_level1.getSelectedItem() != null) {
level1 = (String) spinner_school_level1.getSelectedItem();
}
}
if (addSchoolProgram2.getVisibility() == View.VISIBLE) {
fee2 = registerSchoolFee2.getText().toString();
level2 = null;
if (spinner_school_level2 != null && spinner_school_level2.getSelectedItem() != null) {
level2 = (String) spinner_school_level2.getSelectedItem();
}
}
if (addSchoolProgram3.getVisibility() == View.VISIBLE) {
fee3 = registerSchoolFee3.getText().toString();
level3 = null;
if (spinner_school_level3 != null && spinner_school_level3.getSelectedItem() != null) {
level3 = (String) spinner_school_level3.getSelectedItem();
}
}
if (addSchoolProgram4.getVisibility() == View.VISIBLE) {
fee4 = registerSchoolFee4.getText().toString();
level4 = null;
if (spinner_school_level4 != null && spinner_school_level4.getSelectedItem() != null) {
level4 = (String) spinner_school_level4.getSelectedItem();
}
}
if (addSchoolProgram5.getVisibility() == View.VISIBLE) {
fee5 = registerSchoolFee5.getText().toString();
level5 = null;
if (spinner_school_level5 != null && spinner_school_level5.getSelectedItem() != null) {
level5 = (String) spinner_school_level5.getSelectedItem();
}
}
if (addSchoolProgram6.getVisibility() == View.VISIBLE) {
fee6 = registerSchoolFee6.getText().toString();
level6 = null;
if (spinner_school_level6 != null && spinner_school_level6.getSelectedItem() != null) {
level6 = (String) spinner_school_level6.getSelectedItem();
}
}
if (addSchoolProgram7.getVisibility() == View.VISIBLE) {
fee7 = registerSchoolFee7.getText().toString();
level7 = null;
if (spinner_school_level7 != null && spinner_school_level7.getSelectedItem() != null) {
level7 = (String) spinner_school_level7.getSelectedItem();
}
}
if (addSchoolProgram8.getVisibility() == View.VISIBLE) {
fee8 = registerSchoolFee8.getText().toString();
level8 = null;
if (spinner_school_level8 != null && spinner_school_level8.getSelectedItem() != null) {
level8 = (String) spinner_school_level8.getSelectedItem();
}
}
if (addSchoolProgram9.getVisibility() == View.VISIBLE) {
fee9 = registerSchoolFee9.getText().toString();
level9 = null;
if (spinner_school_level9 != null && spinner_school_level9.getSelectedItem() != null) {
level9 = (String) spinner_school_level9.getSelectedItem();
}
}
if ((name.matches("")) || (address.matches("")) || (phone.matches("")) || (email.matches("")) || (website.matches("")) || (estbdate.matches("")) || (admissionOpen.matches(""))
|| (admissionEnd.matches("")) || (district.matches("")) || (country.matches("")) || (institution.matches("")) || (fee.matches("")) || (level.matches("")) ||
(schoolLogoUpload.getDrawable() == null)
) {
Toast.makeText(this, "Please fill up all the fields", Toast.LENGTH_LONG).show();
} else {
if ((email.matches(emailPattern)) && ((Patterns.WEB_URL.matcher(website)).matches())) {
Bitmap image = ((BitmapDrawable) schoolLogoUpload.getDrawable()).getBitmap();
new UploadImage(image, name, address, phone, email, website, district, country, institution, estbdate, fee, level, fee1, level1, fee2, level2, fee3, level3, fee4, level4, fee5, level5, fee6, level6, fee7, level7,
fee8, level8, fee9, level9, admissionOpen,
admissionEnd).execute();
} else
Toast.makeText(getApplicationContext(), "Invalid website and email address", Toast.LENGTH_LONG).show();
}
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
//spinner_district.setSelection(1);
Spinner spinner_country, spinner_institution, spinner_school_level, spinner_school_level1, spinner_school_level2, spinner_school_level3, spinner_school_level4,
spinner_school_level5, spinner_school_level6, spinner_school_level7, spinner_school_level8, spinner_school_level9;
} else {
Toast.makeText(this, "Please check your internet connection", Toast.LENGTH_LONG).show();
}
break;
case R.id.cancel_school_registration_form:
this.finish();
break;
case R.id.register_school_logo:
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
break;
case R.id.register_school_estdate:
datePickerDialogSchool.show();
break;
case R.id.school_admission_startDate:
schoolAdmissionStartDatePicker.show();
break;
case R.id.school_admission_end_date:
schoolAdmissionEndDatePicker.show();
break;
case R.id.add_more_school_programs:
if (addMoreSchoolProgram.getVisibility() == View.VISIBLE) {
if (addSchoolProgram9.getVisibility() == View.GONE) {
if (addSchoolProgram8.getVisibility() == View.GONE) {
if (addSchoolProgram7.getVisibility() == View.GONE) {
if (addSchoolProgram6.getVisibility() == View.GONE) {
if (addSchoolProgram5.getVisibility() == View.GONE) {
if (addSchoolProgram4.getVisibility() == View.GONE) {
if (addSchoolProgram3.getVisibility() == View.GONE) {
if (addSchoolProgram2.getVisibility() == View.GONE) {
if (addSchoolProgram1.getVisibility() == View.GONE) {
addSchoolProgram1.setVisibility(View.VISIBLE);
} else
addSchoolProgram2.setVisibility(View.VISIBLE);
} else
addSchoolProgram3.setVisibility(View.VISIBLE);
} else
addSchoolProgram4.setVisibility(View.VISIBLE);
} else
addSchoolProgram5.setVisibility(View.VISIBLE);
} else
addSchoolProgram6.setVisibility(View.VISIBLE);
} else
addSchoolProgram7.setVisibility(View.VISIBLE);
} else
addSchoolProgram8.setVisibility(View.VISIBLE);
} else
addSchoolProgram9.setVisibility(View.VISIBLE);
} else
addMoreSchoolProgram.setVisibility(View.GONE);
}
break;
case R.id.register_school_email:
}
}
如何通过提示而不是提示来重置为微调器 微调器值
答案 0 :(得分:1)
您可以使用以下代码来解决问题
admissionEnd).execute();
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
spinner_district.setSelection(0);
使用setPrompt和setSelection