本文介绍了如何保持住对话或禁用解雇时,数据是无效的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在创建一个对话框的形式。
i create a form in a dialog .
我使用验证表单到prevent当数据是空的。
i use validate form to prevent when the data is empty
这是我的对话框
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;}
我尝试这个code和验证工作,但该对话框驳回。
i try with this code and validate works, but the dialog is dismiss.
我试着删除返回;
的验证,但数据直接proccess而无需验证
i try to delete return;
in the validate, but the data directly proccess without validating.
我想,直到数据验证来保存对话框。那怎么办?
i want to hold the dialog until data is verified. how to do that?
请我真的需要帮助。
推荐答案
下面是我做了保留在验证对话框
Here is what I have done to retain dialog on validation
table_array=new String[numOfTables+1];
for(int i=1; i < numOfTables+1; i++)
{
table_array[0]="Select";
table_array[i]=String.valueOf(i);
}
// populate spinner
spinner=new Spinner(context);
spinner.setAdapter( new ArrayAdapter(context,android.R.layout.simple_dropdown_item_1line, table_array));
final AlertDialog d = new AlertDialog.Builder(context)
.setView(spinner)
.setTitle("Select table number")
.setPositiveButton(android.R.string.ok,
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!spinner.getSelectedItem().toString().equals("Select"))
{
d.dismiss();
}
else
{
Toast.makeText(context, "Please select the table number", 0).show();
}
}
});
}
});
d.show();
这篇关于如何保持住对话或禁用解雇时,数据是无效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!