builder.setView(v); builder.setPositiveButton(“ Submit”,新的DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
EditText edituser ;
edituser = (EditText) findViewById(R.id.edit_username);
Database myDB;
myDB = new Database(MainActivity.this);
boolean isInserted = myDB.DataInput(edituser.getText().toString());
if(isInserted == true)
Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
Dialog();
}
})
.setNegativeButton("Cancel",null)
.setCancelable(false);
答案 0 :(得分:-1)
使用try
和catch
builder.setView (v); builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try{
EditText edituser ;
edituser = (EditText) findViewById(R.id.edit_username);
Database myDB;
myDB = new Database(MainActivity.this);
boolean isInserted = myDB.DataInput(edituser.getText().toString());
if(isInserted == true)
Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
Dialog();
}catch (Exception ex) {e.printStackTrace();}
}
})
.setNegativeButton("Cancel",null)
.setCancelable(false);