我收到以下错误:“无法引用以不同方法定义的内部类中的非最终变量”
我应该具体改变什么来避免它?
我正在关注 AlertDialog:
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) {
//I need some actions to be done here
}})
.setNegativeButton("No", null)
.show();
我需要在 AlertDialog 中完成此操作:
String st = editTextSt.getText().toString();
String sp = editTextSp.getText().toString();
SQLiteDbHelper database2 = new SQLiteDbHelper(this);
SQLiteDatabase 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);