您好我试图将所选的RadioButton显示在更新/编辑活动中的相同位置。但我不知道该怎么做。这就是我所做的。我在SQlite中保存了所有String值。并且编辑活动中的getIntent额外。其他字段如EditText可以获得额外的值。我已经阅读了一些关于RadioGroup的例子,我是否必须从RadioGroup getcheckedradiobuttonid中保存整数选择的值,如果是这样,那么如何显示确切的值?请帮忙谢谢
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;
}
在数据库中保存新数据或更新数据
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);
}
获取编辑活动的价值
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);
}
}