// This method will set right value on the togle buttons private void setToggleButtons() { DbAdapter db = new DbAdapter(this); db.open(); // carb togle button Cursor cSettingCarb = db.fetchSettingByName(DbSettings.setting_value_carb_onoff); if (cSettingCarb.getCount() > 0) { cSettingCarb.moveToFirst(); if (cSettingCarb.getInt(cSettingCarb.getColumnIndexOrThrow(DbAdapter.DATABASE_SETTINGS_VALUE)) == 1) { tgCarb.setChecked(true); } else { tgCarb.setChecked(false); } } cSettingCarb.close(); // prot togle button Cursor cSettingProt = db.fetchSettingByName(DbSettings.setting_value_prot_onoff); if (cSettingProt.getCount() > 0) { cSettingProt.moveToFirst(); if (cSettingProt.getInt(cSettingProt.getColumnIndexOrThrow(DbAdapter.DATABASE_SETTINGS_VALUE)) == 1) { tgProt.setChecked(true); } else { tgProt.setChecked(false); } } cSettingProt.close(); // fat togle button Cursor cSettingFat = db.fetchSettingByName(DbSettings.setting_value_fat_onoff); if (cSettingFat.getCount() > 0) { cSettingFat.moveToFirst(); if (cSettingFat.getInt(cSettingFat.getColumnIndexOrThrow(DbAdapter.DATABASE_SETTINGS_VALUE)) == 1) { tgFat.setChecked(true); } else { tgFat.setChecked(false); } } cSettingFat.close(); // kcal togle button Cursor cSettingKcal = db.fetchSettingByName(DbSettings.setting_value_kcal_onoff); if (cSettingKcal.getCount() > 0) { cSettingKcal.moveToFirst(); if (cSettingKcal.getInt(cSettingKcal.getColumnIndexOrThrow(DbAdapter.DATABASE_SETTINGS_VALUE)) == 1) { tgKcal.setChecked(true); } else { tgKcal.setChecked(false); } } cSettingKcal.close(); db.close(); }
// This method will uncheck all radio buttons and check the default one private void setDefaultRadioButton() { rbCarb.setChecked(false); rbProt.setChecked(false); rbFat.setChecked(false); rbKcal.setChecked(false); DbAdapter db = new DbAdapter(this); db.open(); Cursor cSetting = db.fetchSettingByName(DbSettings.setting_value_default); if (cSetting.getCount() > 0) { cSetting.moveToFirst(); defaultValue = cSetting.getInt(cSetting.getColumnIndexOrThrow(DbAdapter.DATABASE_SETTINGS_VALUE)); } else { // set default = carb defaultValue = 1; } cSetting.close(); db.close(); switch (defaultValue) { case 1: rbCarb.setChecked(true); break; case 2: rbProt.setChecked(true); break; case 3: rbFat.setChecked(true); break; case 4: rbKcal.setChecked(true); break; } }