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 6966797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:14:16+00:00 2026-05-27T16:14:16+00:00

GOAL 1: When click the button, if there isn’t any radiobutton checked, it will

  • 0

  1. GOAL 1: When click the button, if there isn’t any radiobutton checked, it will warning user by Toast; if a radiobutton checked, it will take user to new activity (or do smt up on you).

First

public class hanh1_2 extends Activity{

public static int ButID;
@Override

Second, set the button action:

final Button ok2 = (Button) findViewById(R.id.ok2);
    ok2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Set int of ButID = checkedradiobuttonID
                            //If ButID = -1 --> there isn't bt checked
            int ButID = tieng.getCheckedRadioButtonId();
            if (ButID == -1){
                Toast.makeText(hanh1_2.this, "Check a butt pls", Toast.LENGTH_SHORT).show();
            }
            else {
            Intent intent2 = new Intent(hanh1_2.this,hanh1_3.class);
            startActivity(intent2);
            }
        }
    });

Meaningless to advanced, but may helpful for some newbie like me 🙂

  • 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-05-27T16:14:17+00:00Added an answer on May 27, 2026 at 4:14 pm
    1. Have a look at the Form stuff tutorial on the Android dev site. You can supply an OnClickListener to all RadioButtons and keep track of the one selected (if any).

      private OnClickListener radio_listener = new OnClickListener() {
          public void onClick(View v) {
              // Perform action on clicks
              RadioButton rb = (RadioButton) v;
              Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
          }
      };
      

      Alternatively, you can potentially use the RadioGroup’s getCheckedRadioButtonId() method.

    2. As illustrated in one of the other answers: pass the int value as an extra to the Intent you use to launch your second Activity:

      // In first activity
      Intent i = new Intent(FirstActivity.this, SecondActivity.class);
      i.putInt("selected_index", selectedIndex);
      startActivity(i);
      
      // In second activity
      int selectedIndex = getIntent().getExtras().getInt("selected_index");
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal When a user clicks the button, the div in question will: slide down
My goal: the user clicks a button. From the button pops up a two-level
My goal is to let the user click on a specific location on a
My goal is to have a jQuery datepicker pop up when the user clicks
My goal is for the user to fill out one form and use JavaScript
So the goal I am trying to achieve is that when I click on
I have an issue with the browser [BACK] button. Let me explain. There is
My end goal is to create a firefox extension that inserts an HTML button
I want to display a Button inside the ListView . The goal should be
Goal: Right clicking in the listview and choose different option. Problem: There are two

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.