Now intercept part of the code, I now showDialog function is the "OK" button, the return value is 1, click the "Cancel" button, the return value is 0, then the return value according to a, to perform the appropriate action, as follows :
a = showDialog ("Product Name:" + goodsname + "\ n product barcode number:" + ebno + "\ n original product number:" + productnono
+ "\ N The product number:" + eprono + "\ n Total number of goods:" + (Integer.parseInt (productnono) + Integer.parseInt (eprono)), 1) ;/ / update
commodityif (a == 0) / / click the Cancel button
{
return;
}
if (a == 1) / / Click the OK button
{
/ / Update data
database.execSQL ("update t_checkinfo SET number = where barcode =??", new Object [] {(Integer.parseInt (productnono) + Integer.parseInt (eprono)), ebno.toString ()}); / / for commodities Quantity updated
Cursor c2 = database.rawQuery ("select * from t_checkinfo where number =?", New String [] {productnono.toString ()}) ;/ / determine at this time whether the number is equal to the original number of commodity goods, if equal then the data update unsuccessful
if (c2.moveToFirst ())
{
showDialog ("Data Update Failed!", 0);
}
else
{
showDialog ("Data updated successfully!", 0);
}
}
public int showDialog (String msg, int num) {
/ / TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder (InActivity.this);
if (num == 0)
{
builder.setMessage (msg)
. SetPositiveButton ("OK", new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int id) {
a = 1;
}
});
}
if (num == 1)
{
builder.setMessage (msg)
. SetPositiveButton ("OK", new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int id) {
a = 1;
}
}). SetNegativeButton ("Cancel", new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int id) {
a = 0;
}
});
}
AlertDialog alert = builder.create ();
alert.show ();
return a;
}
The question is: (1) the red part is shown below
if written else, running, I want to first
, then click on the dialog box "OK" button after , and then display the "Data updated successfully!" Now I did not click on the "OK" button, the result of two superimposed displayed. Guiqiu reason ah, you big gods.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Logical problems.
showDialog method num is 1,
pass parameters whenThen directly return after show num.
Then again received the return value directly update without waiting for confirmation button.
The reason is this.
Reply:
I guess the landlord this code at run time, a there is an initial value, it appears logical question above.
The landlord at the beginning of a showDialog method to assign to -1, do not have this problem.
ShowDialog better approach is to go in the "OK" in the onClick method, the code logic will be a lot clearer than it is now.
Reply:
Even if the initial value of -1, can not solve the problem. Do not reflect any point after the OK or Cancel.
Because his approach is direct return, without waiting for the user OK or Cancel.
The solution there is:
1 upstairs, perform operations in onClick.
2, the callback function.
Reply:
Thank you very much heroes answer, the current problem has been resolved. Thank you, thank you, ha.
No comments:
Post a Comment