我在对话框中创建一个表单。
我使用验证表单来防止数据为空
这是我的对话
new AlertDialog.Builder(this)
.setTitle(R.string.add_title)
.setView(addView)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
if (wrapper.getCode().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Code belum terisi");return;}
else if (wrapper.getAlamat().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Alamat belum terisi");return;}
else if (wrapper.getBatas().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Informasi batas belum terisi");return;}
else if (wrapper.getLat().equals("Unknown")) {CUtilities.showAlert(MainPetakTetap.this, "Latitude belum terdeteksi");return;}
else if (wrapper.getLon().equals("Unknown")) {CUtilities.showAlert(MainPetakTetap.this, "Longitude belum terdeteksi");return;}
else if (wrapper.getLuas().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Luas belum terisi");return;}
else if (wrapper.getTglA().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Tanggal Awal belum terisi");return;}
else if (wrapper.getTglB().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Tanggal Akhir belum terisi");return;}
else if (wrapper.getUser().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "User Id belum terisi");return;}
final DatabaseConnector dbConnector =
new DatabaseConnector(MainPetakTetap.this);
db = new DatabaseConnector(MainPetakTetap.this);
dbConnector.open();
Cursor cursor = dbConnector.getUser(wrapper);
if (!cursor.moveToFirst()) {
do {
if (cursor!=null && cursor.getCount()==0) {
db.processAddB(wrapper);
constantsCursor.requery();
}
} while (cursor.moveToNext());
}
else{
CUtilities.showAlert(MainPetakTetap.this, "Code yang anda insert sudah terdaftar!"); return;
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
if (db != null) {
db.close();
}
new AlertDialog.Builder(MainPetakTetap.this)
.setMessage("Data telah Tersimpan di aplikasi. Kirim ke Server?")
.setTitle("Pesan")
//.setView(addView)
.setPositiveButton(R.string.kirim,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
String code = wrapper.getCode();
String alamat = wrapper.getAlamat();
String batas = wrapper.getBatas();
String lat = wrapper.getLat();
String lon = wrapper.getLon();
String luas = wrapper.getLuas();
String tglA = wrapper.getTglA();
String tglB = wrapper.getTglB();
String userId = wrapper.getUser();
new ProcessSend().execute(code, alamat, batas, lat, lon, luas, tglA, tglB, userId);
//saveContact(code);
}
})
.setNegativeButton(R.string.batal,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// stop the gps when cancel
lman.removeUpdates(locaListener);
}
}).show();
}
})
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// stop the gps when cancel
lman.removeUpdates(locaListener);
}
}).show();
这是验证
if (wrapper.getCode().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Code belum terisi");return;}
else if (wrapper.getAlamat().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Alamat belum terisi");return;}
else if (wrapper.getBatas().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Informasi batas belum terisi");return;}
else if (wrapper.getLat().equals("Unknown")) {CUtilities.showAlert(MainPetakTetap.this, "Latitude belum terdeteksi");return;}
else if (wrapper.getLon().equals("Unknown")) {CUtilities.showAlert(MainPetakTetap.this, "Longitude belum terdeteksi");return;}
else if (wrapper.getLuas().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Luas belum terisi");return;}
else if (wrapper.getTglA().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Tanggal Awal belum terisi");return;}
else if (wrapper.getTglB().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "Tanggal Akhir belum terisi");return;}
else if (wrapper.getUser().length()==0) {CUtilities.showAlert(MainPetakTetap.this, "User Id belum terisi");return;}
我尝试使用此代码并验证工作,但对话框被关闭。
我尝试return;
在验证中删除,但数据直接处理而不验证。
我想保持对话框,直到数据得到验证。怎么做?
请问我真的需要帮助