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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:52:34+00:00 2026-06-13T08:52:34+00:00

I have created an activity with two buttons at the top. One button to

  • 0

I have created an activity with two buttons at the top. One button to show “SMS Logs” and second to show “Call Logs”.

On clicking “SMS Logs” button, i am dynamically creating textviews and linear layout to show sms logs.

On Clicking “Call Logs”, i am dynamically creating another textviews and linear layout to show call logs.

But the problem is that, once if we click “sms log” button and then we click “call log” button, the previously created linear layouts are not removed and the both(previous layouts and the current layouts) are shown simultaneously.

But i want that the previous layouts should be removed on clicking the second button.

Which function, should i use to remove the previous viewgroups or the layouts. Tell me if you need to read my class file.

Edit:

This is my Activity’s code,

public class General extends Activity
{
    String phone, message;
    TextView Logs;
    View layout, callLayout;
    TextView data, callData, line, callLine;
    Button smsLog, callLog;
    LinearLayout ll, callll;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.general_main);
        Logs = (TextView)findViewById(R.id.Logs);
        layout = findViewById(R.id.layout);
        callLayout = findViewById(R.id.layout);
        smsLog = (Button)findViewById(R.id.smsLogs);
        callLog = (Button)findViewById(R.id.callLogs);
        smsLog.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) 
            {
                callLayout.setVisibility(View.GONE);
                       ll = new LinearLayout(getApplicationContext());
                       ll.setOrientation(LinearLayout.VERTICAL);
                       data = new TextView(getApplicationContext());
                        data.setText("First Line");
                        data.setTextColor(Color.YELLOW);
                        line = new TextView(getApplicationContext());
                        line.setText("Second Line");
                        ((ViewGroup) ll).addView(data);
                        ((ViewGroup) layout).addView(line);
                        ((ViewGroup) layout).addView(ll);
            }
        });


        callLog.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v) 
            {
                layout.setVisibility(View.GONE);
                        callll = new LinearLayout(getApplicationContext());
                        callll.setOrientation(LinearLayout.VERTICAL);
                         callData = new TextView(getApplicationContext());
                            callLine = new TextView(getApplicationContext());
                        callData.setText("Third Line");
                        callLine.setText("Fourth Line");
                        ((ViewGroup) callll).addView(callData);
                        ((ViewGroup) callLayout).addView(callLine);
                        ((ViewGroup) callLayout).addView(callll);
            }
        });
    }
}

I have removed the extra code and made it simple to understand.

  • 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-13T08:52:35+00:00Added an answer on June 13, 2026 at 8:52 am

    You could implement a TabView.

    But having your current setup just change the visibility of one view group to GONE and the other to VISIBLE.

    GONE will make the view invisible and it won’t take up any space anymore.

    EDIT based on the code added to the question

    Both your layout and callLayout are using the same XML view. Implement 2 identical views in your xml and keep one visible and one gone. This way when you set layout or callLayout visibility to GONE they are 2 different ones not the same. So your onClick() will have something like this:

    for smsLog:

    layout.setVisibility(View.GONE);
    callLayout.setVisibility(View.VISIBLE);
    

    for callLog:

    callLayout.setVisibility(View.GONE);
    callLayout.setVisibility(View.VISIBLE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a radio group which contains two buttons, I can select one
I have two buttons on my application. One button starts a new Game (lets
I am trying to display ListView . I have created one activity , in
I have created one class as public class FormActivity extends Activity { TextView tv
I have created two projects. The first one, extracts information of handset and shows
I have four EditText and two buttons namely, save and review button. If i
I have a simple program with one TextView and two Buttons: Button1 and Button2.
I have an activity which displays two fragments: When activity is created, it displays
i have created two buttons and a textbox. the textbox shows the text that
I have an app with two screens, and buttons that switch between them. One

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.