Nishan Khadka
Nishan Khadka

Reputation: 414

I want a alert dialog to come up when a radio button is checked

I have a radio group with 4 radio buttons. And i want alert dialog to pop when either one of two particular radio buttons is checked. How can i Achieve this??

Upvotes: 0

Views: 355

Answers (1)

Muhammad Shan
Muhammad Shan

Reputation: 226

     both    = (RadioButton) findViewById(R.id.both);

     RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rgroup);
    assert radioGroup != null;
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
    {
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            if (veg.isChecked()) {
                proof="veg";
                //Toast.makeText(getApplicationContext(),proof,Toast.LENGTH_SHORT).show();
            } else if(nonv.isChecked()) {
                proof="non veg";
                    //Toast.makeText(getApplicationContext(),proof,Toast.LENGTH_SHORT).show();
            }
            else if (both.isChecked()){
                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("GPS is off");  // GPS not found
        builder.setMessage("Turn on location services"); // Want to enable?
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {

                ConnectToWifi.this.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));

            }
        });
        builder.setNegativeButton("No", null);
        builder.create().show();

            }

        }
    }); 

Upvotes: 2

Related Questions