Skip to content Skip to sidebar Skip to footer

Radio Buttons Showing Only First Option Correct And The Others Showing All Wrong Data In Android

In my questions answers small game i am showing questions and answers from the database file. question is in text view and answers are in radiobuttons.no the data is showing accura

Solution 1:

please try to do like this

case R.id.save_profile:
        if(((RadioButton)findViewById(R.id.radio0)).isChecked()){
            Answer=(RadioButton)findViewById(R.id.radio0)).getText().toString();
        }
       if(((RadioButton)findViewById(R.id.radio1)).isChecked()){
            Answer=(RadioButton)findViewById(R.id.radio0)).getText().toString();
       }  

        // compare here your option......


break;  

after that you need to compare the answer with checked button.

Solution 2:

your code is perfect. it works for me. Just check if your database retrievals and method makeanswer() are correct.

Solution 3:

   rb1=(RadioButton)findViewById(R.id.rb1);
   rb2=(RadioButton)findViewById(R.id.rb2);
   rb3=(RadioButton)findViewById(R.id.rb3);
   rb4=(RadioButton)findViewById(R.id.rb4);

rb1.setText("");//get from database options  
rb2.setText("");//get from database options  
rb3.setText("");//get from database options  
rb4.setText("");//get from database options  //***********onclick of submit button{int rd1=r_group.getCheckedRadioButtonId();
            String textt = "" ;
/************for error if not click on radio btn**********************/if(rd1==-1)

            {
                {   
                AlertDialog ad=new AlertDialog.Builder(Mind_Boost_First.this).create();
                ad.setTitle("error");
                ad.setMessage("plz select any radio button");
                ad.setIcon(R.drawable.cross);
                ad.setButton("ok",new DialogInterface.OnClickListener() {

                    @Override
                    publicvoid onClick(DialogInterface paramDialogInterface, int paramInt) {
                        // TODO Auto-generated method stub

                    }
                });
                ad.show();
                }}  
/****************************** get radio checked to textt**************************/else
            {

                switch(rd1)
                {
                    case R.id.rb1:
                textt =rb1.getText().toString().trim();
                        Log.e("rrrrrrrrbbbbbbbb11111111",""+rb1.getText().toString().trim());
                        break;
                    case R.id.rb2:
                textt = rb2.getText().toString().trim();
                        Log.e("rrrrrrrrbbbbbbbb222222222",""+rb1.getText().toString().trim());
                        break;
                    case R.id.rb3:
                textt = rb3.getText().toString();
                        Log.e("rrrrrrrrbbbbbbbb3333333333",""+rb1.getText().toString().trim());
                        break;
                    case R.id.rb4:
                textt = rb4.getText().toString();
                        Log.e("rrrrrrrrbbbbbbbb4444444444",""+rb1.getText().toString().trim());
                        break;
                  }


/*get correct value in str*/String str=c.getString(6).trim();

                r_group.clearCheck();




                /*reset value of lable */

This is my snippet of code that works perfect for me

Post a Comment for "Radio Buttons Showing Only First Option Correct And The Others Showing All Wrong Data In Android"