我有三個單選按鈕..現在,當我想在單選按鈕之間切換時,我正在使用警報對話框..現在點擊是另一個單選按鈕被選中, NO它不能去以前的單選按鈕..如何在單選按鈕之間切換android
這裏是我的代碼:
RadioGroup radioGroup;
RadioButton pre, during, post;
String lastChecked = "pre"; //This is the Flag which i m using
radioGroup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastCheckedid = radioGroup.getCheckedRadioButtonId();
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
lastCheckedid = radioGroup.getCheckedRadioButtonId();
if (pre.isChecked()) {
lastChecked = "pre";
getlastchecked();
} else if (during.isChecked()) {
lastChecked = "during";
getlastchecked();
} else if (post.isChecked()) {
lastChecked = "post";
getlastchecked();
}
}
});
private void getlastchecked() {
AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(MainActivity.this);
alertDialog2.setTitle("Confirm Delete...");
alertDialog2.setMessage("Are you sure you want delete this post ?");
alertDialog2.setIcon(R.drawable.delete);
alertDialog2.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
imageView1.setImageDrawable(null);
textview_imagename1.setText("");
imageView2.setImageDrawable(null);
textview_imagename2.setText("");
imageView3.setImageDrawable(null);
textview_imagename3.setText("");
}
});
alertDialog2.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (lastCheckedid) {
case R.id.pre:
if (lastChecked.equals("during")){
during.setChecked(true);}
else if (lastCheck.equals("post")){
post.setChecked(true);}
break;
case R.id.during:
if (lastChecked.equals("pre")){
pre.setChecked(true);}
else if (lastCheck.equals("post")){
post.setChecked(true);}
break;
case R.id.post:
if (lastChecked.equals("during")){
during.setChecked(true);}
else if (lastCheck.equals("pre")){
pre.setChecked(true);}
break;
}
}
});
alertDialog2.show();
}
的NO條件是不工作...請幫助
抱歉晚回覆。這個已經解決了我的問題..謝謝你的解決方案。感謝您的時間.. @NitinPatel –
@AbhijitPatil不客氣。 –