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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:26:33+00:00 2026-06-16T01:26:33+00:00

If user clicks NEXT button without selecting option it has to toast a message,

  • 0

enter image description here

If user clicks NEXT button without selecting option it has to toast a message, “pls select any one” else it should goto next screen. I have tried but its not going to next screen, Instead its showing toast”pls select any one” and my code

public class Question1 extends Activity implements OnClickListener {
Button vid, next;
Typeface tp;
TextView tv;
RadioGroup rg;
RadioButton rb;
Button b;
SharedPreferences sp;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.question1);
    sp = getSharedPreferences("AppFile1", 0);

    tv = (TextView) findViewById(R.id.tvQuestion1);

    rg = (RadioGroup) findViewById(R.id.radioGroup1);
    vid = (Button) findViewById(R.id.buttonQuestion1VIdeo);
    next = (Button) findViewById(R.id.buttonQuestion1Next);
    vid.setOnClickListener(this);
    next.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.buttonQuestion1VIdeo:
        Intent i = new Intent(Question1.this, VideoActivity.class);
        startActivity(i);
        break;
    case R.id.buttonQuestion1Next:
        if (next.isSelected()) {
            int selectedId = rg.getCheckedRadioButtonId();
            rb = (RadioButton) findViewById(selectedId);
            String s = rb.getText().toString();
            SharedPreferences.Editor ed = sp.edit();
            ed.putString("q1", s);
            ed.commit();
            Intent ia = new Intent(Question1.this, Question2.class);
            startActivity(ia);

        } else {
            Toast.makeText(getApplicationContext(), "Please Select Answer", 0).show();
        }

        break;
    default:
        break;
    }

}

}

  • 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-16T01:26:34+00:00Added an answer on June 16, 2026 at 1:26 am

    Try with:

    if (rg.getCheckedRadioButtonId()!=-1) {
            int selectedId = rg.getCheckedRadioButtonId();
            rb = (RadioButton) findViewById(selectedId);
            String s = rb.getText().toString();
            SharedPreferences.Editor ed = sp.edit();
            ed.putString("q1", s);
            ed.commit();
            Intent ia = new Intent(Question1.this, Question2.class);
            startActivity(ia);
    
        } else {
            Toast.makeText(getApplicationContext(), "Please Select Answer", 0).show();
        }
    

    The documentation says that if no button is checked, getCheckedRadioButtonId() returns -1.

    Returns the identifier of the selected radio button in this group. Upon empty selection, the returned value is -1.

    Therefore, if you have any value except -1 from that function, you have a selected button.

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

Sidebar

Related Questions

I've built a modal image gallery. When the user clicks next to see next
When user clicks on select box , I want to hide the options menu
When the user clicks on a button, a new ListFragment is displayed. This fragment
When a user clicks a table row, I use jQuery to select the link
When a user clicks a submit button I want the form to be submitted.
I have a list of Strings and every row has a button next to
When the user click on Camera, it open next screen after few seconds it
When user clicks hyperlink on my ASP.NET page, I want a new browser to
If a user clicks the blank row at the bottom of a DataGridView and
When the user clicks add more options, a from is created with javascript document.getElementById('addmore').innerHTML

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.