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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:37:29+00:00 2026-06-17T08:37:29+00:00

Trying to achieve a dynamic UI with facebook like sliding menu and actionbarsherlock .First

  • 0

Trying to achieve a dynamic UI with facebook like sliding menu and actionbarsherlock
.First i have look into android documentation which introduce fragment to handle dynamic button. But with no luck and a week time , i still can’t get it to work anyhow , i guess is my misunderstand on android concept.The slidingbar and actionbarsherlock work without any problem.

I have a HomeScreen.java which contain all my menu and presetation stage
and so far i have created a pagerAdapter1.java that extends FragmentPagerAdapter
, and three example fragment class that handle my work which is task1.java,task2.java
,task3.java simple enough

here is part of my code
HomeScreen.java

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;
public class HomeScreen extends SlidingFragmentActivity {
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_home_screen);
            setBehindContentView(R.layout.menu_frame);
    }

PagerAdapter1.java

public class PagerAdapter1 extends FragmentPagerAdapter  {

    private List<Fragment> fragments;
    public PagerAdapter1(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    public Fragment getItem(int position) {
        return this.fragments.get(position);
    }

    public int getCount() {
        return this.fragments.size();
    }

}

and three task1.java,2,3

    import android.support.v4.app.Fragment;
    public class Tab1Fragment extends Fragment{

onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            if (container == null) {
                return null;
            }
            return (LinearLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false);
        }

I think its better to explain my problem with picture

A homescreen which is a presetation stage , whenever user click on menu , this page will change to the page he want

homescreen

and this is my menu

menu_frame

My problem is how do i include this 3 fragment into my homescreen ? i have tried so many tutorial but it doesn’t work in my situation.Most tutorial are creating fragment with code, i just want to include my 3 task into it

  • 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-17T08:37:30+00:00Added an answer on June 17, 2026 at 8:37 am

    I´ll try to explain this sample code and you use for your need.

    This is the ListFragment of your BehindContent (SlidingMenu):

    public class ColorMenuFragment extends ListFragment {
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            return inflater.inflate(R.layout.list, null);
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            String[] colors = getResources().getStringArray(R.array.color_names);
            ArrayAdapter<String> colorAdapter = new ArrayAdapter<String>(getActivity(), 
                    android.R.layout.simple_list_item_1, android.R.id.text1, colors);
            setListAdapter(colorAdapter);
    //This array is only to fill SlidingMenu with a Simple String Color.
    //I used MergeAdapter from Commonsware to create a very nice SlidingMenu.
        }
    
        @Override
        public void onListItemClick(ListView lv, View v, int position, long id) {
    //This switch case is a listener to select wish item user have been selected,  so it Call
    //ColorFragment, you can change to Task1Fragment, Task2Fragment, Task3Fragment.
            Fragment newContent = null;
            switch (position) {
            case 0:
                newContent = new ColorFragment(R.color.red);
                break;
            case 1:
                newContent = new ColorFragment(R.color.green);
                break;
            case 2:
                newContent = new ColorFragment(R.color.blue);
                break;
            case 3:
                newContent = new ColorFragment(android.R.color.white);
                break;
            case 4:
                newContent = new ColorFragment(android.R.color.black);
                break;
            }
            if (newContent != null)
                switchFragment(newContent);
        }
    
        // the meat of switching the above fragment
        private void switchFragment(Fragment fragment) {
            if (getActivity() == null)
                return;
    
            if (getActivity() instanceof FragmentChangeActivity) {
                FragmentChangeActivity fca = (FragmentChangeActivity) getActivity();
                fca.switchContent(fragment);
            } else if (getActivity() instanceof ResponsiveUIActivity) {
                ResponsiveUIActivity ra = (ResponsiveUIActivity) getActivity();
                ra.switchContent(fragment);
            }
        }
    
    
    }
    

    Here is your BaseActivity Class:

    It dont have swipe, as I could understand, you don’t need this.

    public class FragmentChangeActivity extends BaseActivity {
    
        private Fragment mContent;
    
        public FragmentChangeActivity() {
            super(R.string.changing_fragments);
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // set the Above View
            if (savedInstanceState != null)
                mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
            if (mContent == null)
                mContent = new ColorFragment(R.color.red);  
    
            // set the Above View
                //This will be the first AboveView
            setContentView(R.layout.content_frame);
            getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, mContent)
            .commit();
    
            // set the Behind View
                //This is the SlidingMenu
            setBehindContentView(R.layout.menu_frame);
            getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.menu_frame, new ColorMenuFragment())
            .commit();
    
            // customize the SlidingMenu
                //This is opcional
            getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        }
    
        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            getSupportFragmentManager().putFragment(outState, "mContent", mContent);
        }
    
        public void switchContent(Fragment fragment) {
                // the meat of switching fragment
            mContent = fragment;
            getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_frame, fragment)
            .commit();
            getSlidingMenu().showContent();
        }
    
    }
    

    Ok, So If you want to change the ColorFragment to anything else, do this:

    First, choice the item that you want to use:

    case 0:
                    newContent = new ColorFragment(R.color.red);
                    break;
    

    to:

    case 0:
                newContent = new ArrayListFragment();
                break;
    

    I have made just a arraylist, it is just a simple example, you can do a lot of thing, then you can read about Fragment to learn how to do different things.

        public class ArrayListFragment extends ListFragment {
    
        @Override                               
                public void onActivityCreated(Bundle savedInstanceState) {
                    super.onActivityCreated(savedInstanceState);
                    setListAdapter(new ArrayAdapter<String>(getActivity(),
                            android.R.layout.simple_list_item_1, Listnames.TITLES));
    //Listnames is a class with String[] TITLES;
    
    }
    
            @Override
            public void onListItemClick(ListView l, View v, int position, long id) {
                Log.i("FragmentList2", "Item clicked: " + id);
    
                String item = (String) getListAdapter().getItem(position);
            Toast.makeText(getActivity(), item, Toast.LENGTH_LONG).show();
    
            }
    
        }
    

    Well, if you misunderstood something, just tell me.

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

Sidebar

Related Questions

I have trying to achieve SVG element's animation while adding dynamic DOMs for its
I am trying to achieve dynamic META information so that it will allow META
im trying to achieve something but i dont really know how I have set
I am trying to achieve something like this. The Expandable List consists of the
Lets say that I have a database structure with three tables that look like
When I am trying to create a dynamic instance of Android UI Component, it
I'm trying to achieve a dynamic two dimensional array in C. Whenever the program
I am trying to achieve 2 things with the href links below. First, I
Here is what I'm trying to achieve. I have 3 divs. Let's call them
I have a set of classes which hold state for the database. It's like

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.