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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:44:59+00:00 2026-05-25T23:44:59+00:00

i have a button called ac and when i click on it, i want

  • 0

i have a button called ac and when i click on it, i want to hide my two fragment called a and b, but this is not happening, what do I need to do to make this work?

package cmsc436.lab5;


import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 import android.widget.LinearLayout;

  public class Lab5Activity extends Activity  implements button2interface, button1interface{
/** Called when the activity is first created. */
button1 a;
button2 b ;
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;

@Override
public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);
        a= new button1();
        b=new button2();
     final LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setId(1);
     fragmentManager = getFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();

    //a.getActivity().findViewById(1);
    fragmentTransaction.add(linearLayout.getId(), a);
    fragmentTransaction.add(linearLayout.getId(), b);
    fragmentTransaction.commit();

    final Button ac =new Button(this);
    ac.setText("c button");

    linearLayout.addView(ac);
    setContentView(linearLayout);


    ac.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            fragmentTransaction.hide(a);
            fragmentTransaction.hide(b);

        }
    });

}

@Override
public void buttonClick1() {
    if (b.isHidden()) {
        fragmentTransaction.show(b);
        }
        else {
        fragmentTransaction.hide(b);
        }   
}

@Override
public void buttonClick2() {
    if (a.isHidden()) {
        fragmentTransaction.show(a);
        }
        else {
        fragmentTransaction.hide(a);
        }   
}

}

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

    I haven’t really worked with fragments before, but it looks like you’re trying to re-use a FragmentTransaction that’s already been committed. You don’t want a member variable for your FragmentTransaction; you should create a new one every time you need it:

    public void onClick(View v) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.hide(a);
        fragmentTransaction.hide(b);
        fragmentTransaction.commit();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button called WatchMode. When you click this button, it will close
I have a button: <button id=a onclick=Foo()>Button A</button> When I click this button the
I have a button and on each click I want a different sound to
I have an ASP.NET MVC Page with a button called Start Live Meeting. When
Assume we have a single Windows form with a button called SimpleButton1. The following
I have a WPF window, which contains a button called Cancel. Under ordinary circumstances
I have a UserControl called CustomerFinder for searhing customers. And there is "ADD" button
I have a form with a submit button. I have called a function on
I have one issue with UInavigationcontroller In my firstview i have button.If i click
I want to go to a web page on the click of a button

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.