我想在我的应用程序中选中复选框时禁用主页按钮和返回按钮。我使用的是 4.2.2 版。这是我的代码,它不起作用,当框中检查框时,应用程序停止:
public void HardButtonOnClick(View v)
{
boolean checked1 = ((CheckBox) v).isChecked();
if(checked1)
{
SQLiteDatabase db;
db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
ContentValues values = new ContentValues();
values.put("hardBtn", "YES");
db.update("Setting", values, "id = ?", new String[] { "1" });
Toast.makeText(this, "Hard Button Locked", Toast.LENGTH_LONG).show();
//SharedPreferences pref = getSharedPreferences("pref",0);
//SharedPreferences.Editor edit = pref.edit();
//edit.putString("hard","yes");
//edit.commit();
/* String Lock="yes" ;
Bundle bundle = new Bundle();
bundle.putString("key", Lock);
Intent a = new Intent(Change_setting.this, ChildMode.class);
a.putExtras(bundle);
startActivity(a);*/
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
isLock = true;
}
else
{
SQLiteDatabase db;
db = openOrCreateDatabase("Saftey.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
ContentValues values = new ContentValues();
values.put("hardBtn", "NO");
db.update("Setting", values, "id = ?", new String[] { "1" });
//SharedPreferences pref = getSharedPreferences("pref",0);
//SharedPreferences.Editor edit = pref.edit();
//edit.putString("hard","no");
//edit.commit();
Toast.makeText(this, "Hard Button Un-Locked", Toast.LENGTH_LONG).show();
isLock = false;
}
}
我怎样才能使这项工作?我不想隐藏按钮,我只希望它们在选中复选框时不响应点击。