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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:47:27+00:00 2026-05-20T21:47:27+00:00

Do you need to inflate a view in order to get its id for

  • 0

Do you need to inflate a view in order to get its id for the onClick method? Because when I run my program in the emulator and click on the specific button it does nothing! I want it to go back to the main.xml layout! Do I need to procces the onClick some other way?

public void onClick(View v) {
        switch( v.getId()){
            case R.id.play:
                setContentView(R.layout.play);
                setQuestion();
                break;
            case R.id.level:
                setContentView(R.layout.level);
                if(lvl.equals("1")) {
                    lvl1.setChecked(true);
                }
                if(lvl.equals("2")) {
                    lvl2.setChecked(true);
                }
                if(lvl.equals("3")) {
                    lvl3.setChecked(true);
                }
                if(lvl.equals("4")) {
                    lvl4.setChecked(true);
                }
                if(lvl.equals("5")) {
                    lvl5.setChecked(true);
                }
                 break;
            case R.id.setLevel:
                if(lvl1.isChecked()) {
                    setLevel("1");
                }
                if(lvl2.isChecked()) {
                    setLevel("2");

                }
                if(lvl3.isChecked()) {
                    setLevel("3");
                }
                if(lvl4.isChecked()) {
                    setLevel("4");
                }
                if(lvl5.isChecked()) {
                    setLevel("5");
                }
                setContentView(R.layout.main);
                break;
        }
    }

Here is how I get the views:

setContentView(R.layout.main);

        Button play = (Button)findViewById(R.id.play);
        play.setOnClickListener(this);
        Button level = (Button)findViewById(R.id.level);
        level.setOnClickListener(this);
        Button setLevel = (Button)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.setLevel);

        setLevel.setOnClickListener(this);


        lvl1 = (RadioButton)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.lvl1);

        lvl2 = (RadioButton)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.lvl2);

        lvl3 = (RadioButton)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.lvl3);

        lvl4 = (RadioButton)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.lvl4);

        lvl5 = (RadioButton)getLayoutInflater().inflate(R.layout.level, null).findViewById(R.id.lvl5);

What should I do so that when I click the setLevel button it changes the view back to the main.xml view

  • 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-20T21:47:28+00:00Added an answer on May 20, 2026 at 9:47 pm

    Andrew,

    You may want to make individual onClick() methods for each item. That’s how I handle my click-able objects.

    Example:

    Button play = (Button)findViewById(R.id.play);
    play.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    //perform play button actions here
                }
            });
    

    This way you already have the button object created based on its ID value, and the onClickListener is specifically tailored to that item.

    good luck!

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

Sidebar

Related Questions

I have this: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = (LinearLayout) View.inflate(this,
I have a cusom view derived from TableLayout, and I need to declare String
I need to be able to click an imgview in a listview , which
For EfficientAdapter What code I need to use under onListItemClick to get text of
I am using expandable list view with checkboxex. I need to check all child
I made a custom view to satisfy my need for an easy way to
I'm creating my custom toast mainly because I place it on a grid view
because I need to display something more than just a list in a Fragment.
I need a little help with my custom list view adapter. I'm using the
Say I add a header view to my list view using the typical method

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.