我試圖添加一個對話框,當用戶選擇一個刪除按鈕將刪除指定的行時,將彈出一個對話框。然而,我似乎無法得到適合程序編譯的語法。該行發生錯誤;對話框確認刪除行
MODULEDATABASE.deleteRow(rowId);
Intent intent = new Intent(this, MyCourses.class);
任何建議將不勝感激。
public class ViewCourse extends Activity implements OnClickListener{
Cursor cursor;
database MODULEDATABASE;
String rowId;
Button deleteModule;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_course);
Intent intent = getIntent();
rowId = intent.getStringExtra(MyCourses.TEST);
MODULEDATABASE = new database(ViewCourse.this);
MODULEDATABASE.openToRead(ViewCourse.this);
cursor = MODULEDATABASE.getRow(rowId);
TextView text_modulecode = (TextView)findViewById(R.id.viewModuleCode);
TextView text_modulename = (TextView)findViewById(R.id.viewModuleName);
text_modulecode.setText(cursor.getString(cursor.getColumnIndex(database.KEY_MODULECODE)));
text_modulename.setText(cursor.getString(cursor.getColumnIndex(database.KEY_MODULENAME)));
deleteModule = (Button)findViewById(R.id.deleteButton);
deleteModule.setOnClickListener(this);
}
public void onClick (View deleteModule)
{
Dialog(rowId);
}
public void Dialog (String rowId) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.confirmDelete)
.setPositiveButton(R.string.confirmDelete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MODULEDATABASE = new database(ViewCourse.this);
MODULEDATABASE.deleteRow(rowId);
Intent intent = new Intent(this, MyCourses.class);
startActivity(intent);
}
})
.setNegativeButton(R.string.confirmDelete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
}
}
有什麼錯誤? –
不能在不同的方法中定義的內部類中引用非最終變量rowId – Calgar99
請參閱我的更新答案。 –