public class Example
{
String sp,st;
SQLiteDatabase database, database2;
void func()
{
new AlertDialog.Builder(view.getContext())
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Confirm")
.setMessage("Are you sure?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
String st = editTextSt.getText().toString();
String sp = editTextSp.getText().toString();
database2 = new SQLiteDbHelper(this);
database = database2.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SQLiteDbHelper.COLUMN_NAME_SP, sp);
values.put(SQLiteDbHelper.COLUMN_NAME_ST, st);
long insertId = database.insert(SQLiteDbHelper.TABLE_NAME, null, values);
//I want to call it here
}})
.setNegativeButton("No", null)
.show();
}
我想調用AlertDialog內部的AlertDialog:
new AlertDialog.Builder(this)
.setMessage("Saved!")
.setNeutralButton("OK", null)
.show();
應該怎麼實現?
如果我按照上面的代碼,就會報錯:** The constructor AlertDialog.Builder(new DialogInterface.OnClickListener(){}) is undefined **
試試:
new AlertDialog.Builder(Example.this)
.setMessage("Saved!")
.setNeutralButton("OK", null)
.show();
滿足條件是類Example是一個activity
比如:
public class Example extends Activity
如果不是上面的情況,用這樣:
new AlertDialog.Builder(view.getContext())
.setMessage("Saved!")
.setNeutralButton("OK", null)
.show();