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

  • Home
  • SEARCH
  • 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 6203715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:57:48+00:00 2026-05-24T04:57:48+00:00

I have a LinearLayout which I’ve looped a number of new Button objects into.

  • 0

I have a LinearLayout which I’ve looped a number of new Button objects into. How do I go about clearing that div correctly (eg removing all the buttons)? I’ve tried a number of times (unsuccessfully) to do this, but have nothing to show for it.

** edit **

I’m not sure if this helps, but in flex/AS3 I would do something like:

while(myView.numChildren) myView.removeChildAt(0);

** a little code **

View col1 = findViewById(R.id.col1);
for(final Map.Entry<String,HashMap<String,String>> entry : _nav.entrySet()) {
    Button item = new Button(this);
    item.setText(entry.getKey());
    item.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            openCol2(entry);
        }
    });
    ((LinearLayout) col1).addView(item);
}

private final void openCol2(Map.Entry<String,HashMap<String,String>> entry) {
    View col2 = findViewById(R.id.col2);
    // here is where I want to clean out col2. Right before I add more buttons.

    for(int i = 0; i < _nav.size(); ++i) {
        Button item = new Button(this);
        //item.setText(entry.getKey());
        ((LinearLayout) col2).addView(item);
    }
}
  • 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-24T04:57:50+00:00Added an answer on May 24, 2026 at 4:57 am

    Try this

    LinearLayout col2 = (LinearLayout)findViewById(R.id.col2);
    col2.removeAllViews();
    

    Assumption: R.id.col2 is of LinearLayout type else to make it more generic typecast it to ViewGroup. Hope this help!!!

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

Sidebar

Related Questions

I have a LinearLayout that contains sublayouts which essentially mimick a 3x2 grid. Each
I have a LinearLayout which I wanna inflate into my SectionedAdapter as a Header
I have a LinearLayout, which only contains one button. I want this button to
I have a horizontal LinearLayout, inside which I have 2 TextViews. Let's say that
I have a LinearLayout which has a background image (a 9 patched png file).
I have this XML code which generates a button, a textview and another button,
I have an application, which has a Spinner that I want populated with some
I have a parent LinearLayout in which has some ImageView s, now I set
I have a project using a ViewPager which works correctly: I can page from
I have a linear layout that contains 6 images, which span the linear layout

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.