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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:46:15+00:00 2026-05-22T23:46:15+00:00

I have one Activity in that there are no Button s but I have

  • 0

I have one Activity in that there are no Buttons but I have coded it in such a way that another Activity comes, now in this second Activity there are three Buttons, on which when I click all inflating different respective activities.
In this second Activity there I have added one more Button, on clicking this 4th Button I don’t want another Activity to come in foreground instead i just want another layout to be inflated(I don’t wanna change the Activity)
In that layout(which i need to inflate) I have a ListView which has a list of certain sites, when this layout is inflated the list of sites should be shown and as i click on there sites its should take me to that webpage.

PROBLEM 1:
How to inflate just the xml on click of the 4th Button without changing the Activity.

PROBLEM 2:
When the xml is inflated and if I click on BackButton the Activity containing all the 4 Buttons should be displayed.

Here is the code that I’m using to inflate another xml:

fourthButton.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        callingMore();
    }
});
private void callingMore() {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.web_site_list_xml, (ViewGroup)findViewById(R.id.site_list));
}

BUT this code gives a force close and no xml is being inflated and if I use setContentView( R.layout.web_site_list_xml) inside callingMore() method
the xml is inflated but that xml doesn’t show anything and then if I hit BackButton, the Activity that has all 4 Buttons isn’t shown.

  • 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-22T23:46:15+00:00Added an answer on May 22, 2026 at 11:46 pm

    I tried this code..hope helps to you..

    1.layout_existed.xml

      <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/existedlayout"
        >
       <Button  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Clicck to inflate view"
        android:id="@+id/button"
        />
    </LinearLayout>   
    

    2.layout_toinfliate.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <TextView
      android:id="@+id/mytext"
      android:text="You inflated me..i added to u r layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      />
    </LinearLayout>
    

    3.LayoutInflateDemo.java

      public class LayoutInflateDemo extends Activity {
    
        private LinearLayout layoutToAdd;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_existed);
            layoutToAdd = (LinearLayout) findViewById(R.id.existedlayout);
    
            Button button = (Button) findViewById(R.id.button);
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    LayoutInflater inflater = LayoutInflater
                            .from(getApplicationContext());
                    View view = inflater.inflate(R.layout.layout_toinfliate, null);
                    layoutToAdd.addView(view);
    
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one SubjectTabActivity and i need to show listview on this activity. But
Cant figure this out (am a noob) but I have a default activity that
I have a design of activities like this I have one main activity and
I have an ArrayList of objects in one activity and I need this arrayList
This is my situation. I have two activities: ONE and TWO. In TWO activity
So I have different layouts for this one Activity. And I have different classes
hey there i have this code that should save a file from sql server
hey there guys and girls i have this code that saves json as a
My situation is following. I have one Activity that contains three main parts. At
I am trying to display ListView . I have created one activity , in

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.