Click here to Skip to main content
15,307,117 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i have a tabhost fragment which contains 3 tabs and in the 3rd tab i have a tabhost which contains 2 tabs and also i have a navigation drawer.I am trying to set the current tab in second tabhost value but i am unable to do that.
This is my code for first fragment which contains 3 tabs

    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(
    				getTabView(mTabHost.getContext(), R.drawable.tab_indicator_feeds)), FeedsFragment.class, b);
    
    mTabHost.addTab(
    				mTabHost.newTabSpec("MyContacts")
    						.setIndicator(getTabView(mTabHost.getContext(), R.drawable.tab_indicator_mycontacts)),
    				ContactsFragment.class, b);
    mTabHost.addTab(
    				mTabHost.newTabSpec("custom")
    						.setIndicator(getTabView(mTabHost.getContext(), R.drawable.tab_indicator_notifications)),
    				MessageAndNotificationFragment.class, b);
    mTabHost.setCurrentTab(tabValue);
    	mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
    
    			@Override
    			public void onTabChanged(String tabId) {
    				// TODO Auto-generated method stub
    				if (mTabHost.getCurrentTab() == 0) {
    					FeedsFragment mFragment = new FeedsFragment();
    					mCurrentChildFragmentInterface.CurrentChildFragment(mFragment);
    					HomeActivity activity = (HomeActivity) getActivity();
    					activity.setTitleText("Welcome " + pref.getUserName());
    				}
    				if (mTabHost.getCurrentTab() == 1) {
    					Fragment1 mFragment = new Fragment1();
    					mCurrentChildFragmentInterface.CurrentChildFragment(mFragment);
    					HomeActivity activity = (HomeActivity) getActivity();
    					activity.setTitleText("Contacts");
    				}
    				if (mTabHost.getCurrentTab() == 2) {
    
    					MessageAndNotificationFragment mFragment = new MessageAndNotificationFragment();
    					mCurrentChildFragmentInterface.CurrentChildFragment(mFragment);
    					HomeActivity activity = (HomeActivity) getActivity();
    					activity.setTitleText("Message & Notification");
    				}
    
    			}
    
    		});

and the code for the third tab which contains two tabs is:

    public MessageAndNotificationFragment()
    	{
    		
    	}
    	
    	public static MessageAndNotificationFragment newInstance(int selectedValue) {
    	    MessageAndNotificationFragment f = new MessageAndNotificationFragment();
            Bundle b = new Bundle();
            b.putInt("selectedValue", selectedValue);
            f.setArguments(b);
            Log.i("newInstance", String.valueOf(selectedValue));
            return f;
    
        }
    
        @Override
        public void onAttach(Activity activity) {
            // TODO Auto-generated method stub
            super.onAttach(activity);
            selectedTabValue = getArguments().getInt("selectedValue");
            
        }
    mTabHost = new FragmentTabHost(getActivity());
    		mTabHost.setup(getActivity(), getChildFragmentManager(),
    				R.id.menu_settings);
    		Bundle b = new Bundle();
    		b.putString("key", "ssss");
    		mTabHost.addTab(
    				mTabHost.newTabSpec("simple").setIndicator(
    						getTabView(mTabHost.getContext(),
    								R.drawable.message_icon, "Message")),
    				MessageFragments.class, b);
    		//
    		b = new Bundle();
    		b.putString("key", "Conssstacts");
    		mTabHost.addTab(
    				mTabHost.newTabSpec("contacts").setIndicator(
    						getTabView(mTabHost.getContext(),
    								R.drawable.notification_icon, "Notification")),
    				NotificationFragments.class, b);
    		mTabHost.setCurrentTab(selectedTabValue);

i want that if i click from the navigation drawer the selected tab should be 1(i.e second tab) in messageandnotification tab
Posted
Updated 22-Dec-15 23:37pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900