Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:43:46+00:00 2026-06-15T11:43:46+00:00

So, what I am trying to do here is to have a main activity

  • 0

So, what I am trying to do here is to have a main activity where, if the requirements are met(correct username, password, and male radio button is checked and not female), the VM switches to the “Success” activity. If it does not meet any of those 3 requirements the VM switches to the “Failed” activity when the button is pressed. I have it working correctly except for the Radio Buttons.

I created a RadioGroup on the layout, but I’m not sure how to implement it in the class itself. I assumed you had to find the ID, override the listener etc etc…but it’s not working correctly. Any ideas? I took out most of the RadioGroup properties before posting this so it would be less muddled.

Main Activity

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener
{
    Button button;
    EditText login;
    EditText password;
    RadioGroup mRadioGroup;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button)findViewById(R.id.button1);
        login =(EditText)findViewById(R.id.editText1);
        password =(EditText)findViewById(R.id.editText2);
        button.setOnClickListener(new View.OnClickListener()  
    {
        @Override
        public void onClick(View view)
        {
            String L,P;             

            L = login.getText().toString();
            P = password.getText().toString();


            if(L.equals("name") && P.equals("123456"))
            {
                Intent intent = new Intent();  
                intent.setClass(MainActivity.this,Welcome.class);
                startActivity(intent);
            }
            else
            {
                Intent intent1 = new Intent();
                intent1.setClass(MainActivity.this,Failed.class);
                startActivity(intent1);
            }
      }   
    });




}



  /*  public void onRadioButtonClicked(View view) 
    {
        boolean checked = ((RadioButton) view).isChecked();

        switch(view.getId()) 
        {
            case R.id.radio1:
                if (checked)
                {
                Intent intent4 = new Intent();
                intent4.setClass(MainActivity.this,Welcome.class);
                startActivity(intent4);
                }
                break;
            case R.id.radio0:
                if (checked)
                {
                Intent intent2 = new Intent();
                intent2.setClass(MainActivity.this,Failed.class);
                startActivity(intent2);
                }
                break;
                }
                }
      */



    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }



    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) 
    {
        // TODO Auto-generated method stub

    }


}

Failed Activity

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Failed extends Activity
{
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.failed);
        button = (Button)findViewById(R.id.button1);       
        button.setOnClickListener(new View.OnClickListener()


    {
        @Override
        public void onClick(View view)
        {
            Intent intent3 = new Intent();
            intent3.setClass(Failed.this,MainActivity.class);
            startActivity(intent3);
        }

    });
}
}

Success Activity

import android.app.Activity;
import android.os.Bundle;

public class Welcome extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.success);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:43:47+00:00Added an answer on June 15, 2026 at 11:43 am

    Try this to get the value of the selected RadioButton and use it to check specific conditions in your code :

    private RadioGroup radioOptionGrp;
    private RadioButton radioOptBtn;
    
    //Get Reference to Radio group which holds the radio buttons
    radioOptionGrp = (RadioGroup) findViewById(R.id.radioOpt);
    
    //Get id of selected radioButton
    int selectOptId = radioOptionGrp.getCheckedRadioButtonId();
    
    //Get Reference to the Selected RadioButton
    radioOptBtn = (RadioButton) findViewById(selectOptId);
    
    //Get value of the selected Radio button
    String value = radioOptBtn.getText().toString();    
    

    Hope this helps!! Here is a sample example code you can download from GitHub to see how RadioButtons work https://github.com/asabbarwal/SimpleRadioButton

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here I am trying to implement the jQuery I have two main files one
I have a Main-Activity which displays several spinners. With a Toggle-Button in the Main-Activity
Ok here I have a switch case statement which is falling through and trying
I have a problem here im trying to upload a file first time it
I have a bunch of divs I'm trying to organize here. The ones I'm
i'm new here and i have a question. I am trying to insert a
Trying to have my PHP script return some SQL table queries. Here's my script
I have an interesting problem here I've been trying to solve for the last
Okay here is what I'm trying to do: I have a model object that
Here is what I am trying to do: I have a <h1> element, a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.