0

How to pass intent values based on the radio button checked, and intent should be started only after clicking the button,and the values should be passed based on the swith case statement here is my code please help me out..

package com.example.simplemath;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.util.Log;

public class Settings extends Activity {
    OnCheckedChangeListener listner = null;
    OnCheckedChangeListener listner2 = null;
    int level = 0;
    int TotalQues = 0;
    int click = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);

        Bundle b = getIntent().getExtras();
        click = b.getInt("click");

        Typeface custom_font = Typeface.createFromAsset(getAssets(),
                "fonts/SofadiOne-Regular.ttf");
        Typeface custom_font1 = Typeface.createFromAsset(getAssets(),
                "fonts/belligerent.ttf");

        TextView heading1 = (TextView) findViewById(R.id.textView1);
        heading1.setTypeface(custom_font);
        TextView heading2 = (TextView) findViewById(R.id.textView2);
        heading2.setTypeface(custom_font);

        RadioGroup difficulty = (RadioGroup) findViewById(R.id.radioGroup1);

        difficulty.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (group.getCheckedRadioButtonId()) {
                case R.id.radioButton1:
                    Log.d("info", "one");
                    Intent intent1 = new Intent(Settings.this, Third.class);
                    level = 1;
                    intent1.putExtra("level", level);
                    intent1.putExtra("click", click);
                    // startActivity(intent1);
                    break;

                case R.id.radioButton2:
                    Log.d("info", "two");
                    Intent intent2 = new Intent(Settings.this, Third.class);
                    level = 2;
                    intent2.putExtra("level", level);
                    intent2.putExtra("click", click);
                    // startActivity(intent2);
                    break;

                case R.id.radioButton3:
                    Log.d("info", "three");
                    Intent intent3 = new Intent(Settings.this, Third.class);
                    level = 3;
                    intent3.putExtra("level", level);
                    intent3.putExtra("click", click);
                    // startActivity(intent2);
                    break;
                }

            }
        });
        RadioGroup NoOfQuestions = (RadioGroup) findViewById(R.id.radioGroup2);

        NoOfQuestions.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (group.getCheckedRadioButtonId()) {
                case R.id.radioButton4:
                    Log.d("info", "four");
                    Intent intent4 = new Intent(Settings.this, Third.class);
                    Bundle NoTwenty = new Bundle();
                    TotalQues = 1;
                    NoTwenty.putInt("NoQuestions", TotalQues);
                    intent4.putExtras(NoTwenty);
                    // startActivity(intent4);
                    break;

                case R.id.radioButton5:
                    Log.d("info", "five");
                    Intent intent5 = new Intent(Settings.this, Third.class);
                    Bundle NoThirty = new Bundle();
                    TotalQues = 1;
                    NoThirty.putInt("NoQuestions", TotalQues);
                    intent5.putExtras(NoThirty);
                    // startActivity(intent5);
                    break;

                case R.id.radioButton6:
                    Log.d("info", "six");
                    Intent intent6 = new Intent(Settings.this, Third.class);
                    Bundle NoFourty = new Bundle();
                    TotalQues = 1;
                    NoFourty.putInt("NoQuestions", TotalQues);
                    intent6.putExtras(NoFourty);
                    // startActivity(intent6);
                    break;
                }

            }
        });

        RadioButton easy = (RadioButton) findViewById(R.id.radioButton1);
        easy.setTypeface(custom_font1);
        RadioButton medium = (RadioButton) findViewById(R.id.radioButton2);
        medium.setTypeface(custom_font1);
        RadioButton hard = (RadioButton) findViewById(R.id.radioButton3);
        hard.setTypeface(custom_font1);

        RadioButton twenty = (RadioButton) findViewById(R.id.radioButton4);
        twenty.setTypeface(custom_font1);
        RadioButton thirty = (RadioButton) findViewById(R.id.radioButton5);
        thirty.setTypeface(custom_font1);
        RadioButton fourty = (RadioButton) findViewById(R.id.radioButton6);
        fourty.setTypeface(custom_font1);

        Button submit = (Button) findViewById(R.id.button1);
        submit.setTypeface(custom_font);
        submit.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(Settings.this, Third.class));
            }
        });

    }

}
canova
  • 3,965
  • 2
  • 22
  • 39

1 Answers1

0

Use the following one inside OnClickListener of RadioGroup Button.

AlertDialogBuilder voteBuilder = new AlertDialogBuilder(baseContext);

        final Context context = voteBuilder.getThemeContext();

        voteBuilder.setTitle("Vote");

        LayoutInflater inflater = voteBuilder.getLayoutInflater();

        View viewVote = inflater.inflate(R.layout.eip_vote_popup, null, false);

        TextView qsnText = (TextView) viewVote.findViewById(R.id.textPollingQuestion);
        qsnText.setText(description + "?");

        final RadioButton radioPositive = (RadioButton) viewVote.findViewById(R.id.radioPositive);
        final RadioButton radioNegative = (RadioButton) viewVote.findViewById(R.id.radioNegative);

        if (pollType.equals("AD")) {
            radioPositive.setText("Agree");
            radioNegative.setText("Disagree");
        } else {
            radioPositive.setText("Yes");
            radioNegative.setText("No");
        }

        voteBuilder.setView(viewVote);

        voteBuilder.setNegativeButton("Cancel", null);
        voteBuilder.setPositiveButton("Vote", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        voteBuilder.setCancelable(true);

        final AlertDialog dialog = voteBuilder.show();
        dialog.setCanceledOnTouchOutside(true);

        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!radioPositive.isChecked() && !radioNegative.isChecked()) {
                    Toast.makeText(context, "Select your opinion", Toast.LENGTH_SHORT).show();
                    return;
                }

                //EIPService service = new EIPService(context);
                //service.SaveUserPoll(pollingId, radioPositive.isChecked());
                dialog.dismiss();
            }
        });

instead of Service , you call the necessary Intent. Dont use Switch cases,sometimes it arises the problem .

raguM.tech.
  • 183
  • 11