i am using the following project

https://github.com/akotoe/android-slide-out-menu.git to develop slide out menu application.

How to run different activities in the same view by clicking the list in slide-menu.

for example if i click on item 1 i would like to parse one XML file in a separate activity and add that activity as a child to this parent view.because on each item click i would like to parse a separate XML file and also i would like to represent that parsed data in a separate layout file.so i need an activity to do that and i want that activity to be added as a child to this parent view.

how can i do this can any one help me in doing this.

if i start a new Intent (startactivity) it is navigating to me a different page. where i can't see this parent page.

有帮助吗?

解决方案

UI components that can be embedded inside your activity should be derived from Fragment rather than Activity. When converting your child activities into fragments, you will need to override onCreateView instead of onCreate in order to load the fragment's layout.

In your main activity's layout, you can directly insert the fragment you want to show initially, and give that fragment an ID. Then you can use code to replace the fragment with that ID with a different fragment.

This is a good place to get started: http://developer.android.com/guide/components/fragments.html

This is too big a topic for me to cover everything - you really should look at the Android developer resources - but here are some examples.

As I said, you can put the initial fragment directly into your activity layout. "Fragment" is located on the "Layouts" tab of the layout editor. You give that fragment placeholder an "Id" you can use to identify it as well as the "Name" of the fragment class that will be there to start with.

Then when it's time to switch the fragment, you can use code like this:

// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment
transaction.replace(R.id.fragment_container, newFragment);

// Commit the transaction
transaction.commit();

其他提示

You can't nest activity in another one. But you can use Fragment instread. When click the item just swith to right Fragment by FragmentManager.

Check this Answer first

How do I create a header or footer button bar for my Android application


You can have one Master activity in your project,

Say, MainActivity.java

in that main activity write code for the sliding menu

@Override
    public void onCreate(Bundle inState) {
        super.onCreate(inState);

        mMenuDrawer = new MenuDrawerManager(this, MenuDrawer.MENU_DRAG_CONTENT,
                MenuDrawer.MENU_POSITION_RIGHT);

        mMenuDrawer.setContentView(R.layout.appui);
        mMenuDrawer.setMenuView(R.layout.slide_menu_ui);

    }

In this same activity, initialize your menu components and write listeners for them.

Now,

In your every other Activities extends from MainActivity

and you are done.!!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top