[Solved] switch a Button and Get a different at the Bottom


Create a new Fragment that describes what you want to do in each pane. For example,

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ButtonOneFragment extends Fragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (container != null) {
            container.removeAllViews();
        }
        return inflater.inflate(R.layout.button_one_fragment, container, false);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}

In your MainActivity, or in whichever class controls the the tabs, call a fragment transaction whenever the selected tab changes:

// For AppCompat use getSupportFragmentManager
Fragment fragment = new DefaultFragment();
FragmentManager fragmentManager = getFragmentManager();

if (selectedPane == R.id.buttonOne) {
    fragment = new ButtonOneFragment();
} else if (selectedPane == R.id.buttonTwo) {
    fragment = new ButtonTwoFragment();
} else if (selectedPane == R.id.buttonThree) {
    fragment = new ButtonThreeFragment();
}

fragmentManager.beginTransaction()
                .replace(R.id.container, fragment)
                .commit();

1

solved switch a Button and Get a different at the Bottom