Hi I'm trying to get the selected RadioButton to be displayed in the same position in the update/edit activity. But I did not know how to do this. This is what I have been done. I saved all the String value in SQlite. And getIntent extra in the edit activity. Other field such as EditText can get the extra value. I have read some examples about RadioGroup, is it I have to save the integer selected value from RadioGroup getcheckedradiobuttonid, and if that's the way, how to display the exact value ? please help thank you
public void onClick(View v) {
switch (v.getId()) {
case R.id.rb_tiang_besi:
if (RBTiangBesi.isChecked()) {
RBTiangBeton.setChecked(false);
RBTiangKayu.setChecked(false);
TiangBesi = 1;
TiangBeton = 0;
TiangKayu = 0;
} else {
RBTiangBesi.setChecked(false);
TiangBesi = 0;
TiangBeton = 0;
TiangKayu = 0;
}
break;
case R.id.rb_tiang_beton:
if (RBTiangBeton.isChecked()) {
RBTiangBesi.setChecked(false);
RBTiangKayu.setChecked(false);
TiangBeton = 1;
TiangBesi = 0;
TiangKayu = 0;
} else {
TiangBeton = 0;
TiangBesi = 0;
TiangKayu = 0;
}
break;
case R.id.rb_tiang_kayu:
if (RBTiangKayu.isChecked()) {
RBTiangBeton.setChecked(false);
RBTiangBesi.setChecked(false);
TiangKayu = 1;
TiangBesi = 0;
TiangBeton = 0;
} else {
TiangKayu = 0;
TiangBesi = 0;
TiangBeton = 0;
}
break;
}
Save new or update data in the database
if (action_flag.equals("add")) {
newItemDatabaseID = databaseHandler.saveInspectionMV(details);
if (newItemDatabaseID != null || !newItemDatabaseID.isEmpty()) {
Intent detailIntent = new Intent(InspectionMVActivityTabs.this,
MainActivity.class);
detailIntent.putExtra("COL_ID", "" + newItemDatabaseID);
startActivityForResult(detailIntent, REQUEST_CODE_ADD);
Toast.makeText(getBaseContext(), "Data tersimpan!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getBaseContext(), "Data tidak tersimpan!",
Toast.LENGTH_SHORT).show();
}
} else if (action_flag.equals("edit")) {
boolean flag = databaseHandler.updateInspectionsMV(itemID,
details);
if (flag) {
Toast.makeText(getBaseContext(), "Data terbaharui!",
Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(getBaseContext(), "Data gagal terbaharui!",
Toast.LENGTH_SHORT).show();
}
Intent productIntent = new Intent(this, MainActivity.class);
finish();
startActivity(productIntent);
}
Getting value in edit activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity();
itemID = getActivity().getIntent().getStringExtra("COL_ID");
}
private void setItemContents() {
if (itemID != null) {
ItemsDetails details = databaseHandler.getInspectionsMVItemDetailsFromID(itemID);
editTextNoTiang.setText("" + details.getNoTiang());
editTextKeterangan.setText("" + details.getketerangan());
editTextSaran.setText(""+ details.getSaran());
// My problem here how actually the right way to do this please help???
int selectedId = RBJenisTiang.getCheckedRadioButtonId();
RBTiangBesi = (RadioButton) view.findViewById(selectedId);
RBTiangBeton = (RadioButton) view.findViewById(selectedId);
RBTiangKayu = (RadioButton) view.findViewById(selectedId);
RBJenisTiang.setSelected(true);
}
}