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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:34:46+00:00 2026-05-31T05:34:46+00:00

I want to swap two button positions when we click on toggle button. I

  • 0

I want to swap two button positions when we click on toggle button. I have tried a lot but haven’t got a success. So if anyone knows how to do this please suggest me.
Thanks all.

  • 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-31T05:34:47+00:00Added an answer on May 31, 2026 at 5:34 am

    You could try a sneaky workaround using View.setVisibility(). Start with res/layout/main.xml:

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
            <Button
                android:id="@+id/switcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Switch"
                android:onClick="switchButtons" />
            <Button
                android:id="@+id/buttonA1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button A" />
            <Button
                android:id="@+id/buttonB1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button B" />
            <Button
                android:id="@+id/buttonB2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button B"
                android:visibility="gone" />
            <Button
                android:id="@+id/buttonA2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button A"
                android:visibility="gone" />
    
    </LinearLayout>
    

    And now we have an Activity to put this layout in:

    public class Foo extends Activity {
    
        Button switcher;
        Button A1;
        Button A2;
        Button B1;
        Button B2;
        boolean buttons1AreVisible = true;
    
        protected void onCreate(Bundle allthethings) {
            super.onCreate(allthethings);
            setContentView(R.layout.main);
    
            switcher = findViewById(R.id.switcher);
            A1 = findViewById(R.id.buttonA1);
            A2 = findViewById(R.id.buttonA2);
            B1 = findViewById(R.id.buttonB1);
            B2 = findViewById(R.id.buttonB2);
        }
    
        private void switchButtons() {
            if (buttons1AreVisible) {
                A1.setVisibility(View.GONE);
                B1.setVisibility(View.GONE);
                B2.setVisibility(View.VISIBLE);
                A2.setVisibility(View.VISIBLE);
            } else {
                A1.setVisibility(View.VISIBLE);
                B1.setVisibility(View.VISIBLE);
                B2.setVisibility(View.GONE);
                A2.setVisibility(View.GONE);
            }
    
            buttons1AreVisible = !buttons1AreVisible;
        }
    }
    

    All that remains is for you to assign onClick() methods to the four buttons.

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

Sidebar

Related Questions

I want to swap the values from two rows in a table. I have
I have a table called ticket in which I want to swap two rows
Firstly sorry about my grammar. I have two ImageViews and I want to swap
I want to swap two integers, and I want to know which of these
I want to swap two fragment in an activity via animation.Suppose PageA is for
In most languages, if you want to swap two variables, it's something like: var
I created a custom event called slides.swap but I want to prevent the event
want to have a Hyperlink-Button in a gridView in which I can display a
I have structure like this below. Now, I want swap 2 structures. public struct
I want to swap background images with the fade effect , I tried this:

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.