TrulyXax TrulyXax - 3 months ago 19
Android Question

Changing displaying layout on button click

I have a custom circle layout with rotation feature and 4 views as buttons.
On main_activity i have 2 layouts :
-circle layout
-relative layout(Container)

What i want is:
-when the user taps on a button from circle layout, i want the container to be changed with another layout with another views.

This is the initialization of container:

displayLayout = (RelativeLayout) findViewById(R.id.fragment_container);


Initialization of Circle layout:

circleLayout = (CircleLayout) findViewById(R.id.circle_layout);


The tap event occurs on this method:

public void onItemClick(View view) {

displayLayout.removeAllViews();
-- What should i do here? --
}


I want that the new xml (newpage.xml) to be replaced in container.

Any sugestions to be done?
Thanks a lot!

Answer

you need to do it with fragments as shown in below, to replace view

check fragments in android(https://developer.android.com/reference/android/app/Fragment.html)

public void onItemClick(View view) {
        //displayLayout.removeAllViews();
        // Create new fragment and transaction
        Fragment newFragment = new ExampleFragment();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack if needed
        transaction.replace(R.id.fragment_container, newFragment);
        transaction.addToBackStack(null);
        // Commit the transaction
        transaction.commit();
    }

check http://sapandiwakar.in/replacing-fragments/

check example http://notionink.wikidot.com/rajeshbabu