2

I want to create a layout in which upper half is just some area with normal views and lower half is a tab layout .

something like this

I've seen some examples but they're all how to create tabs at activity level i.e by extending TabHostActivity which covers all the activity area. So i decided to create 2 fragments in the activity ,in which lower fragment will have the tablayout. But the problem is i cant make this fragment class extend Fragment as well as TabHostActivity... So any help how could i implement this ?

Here's the lower fragment's code -

public class PFrag extends Fragment {
    View mRoot;
    TabHost tabHost;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRoot = inflater.inflate(R.layout.payfrag, container, false);
        try {
            Resources resources = getResources();
            tabHost = (TabHost)mRoot.findViewById(R.id.tabHost);

            Intent netbintent = new  Intent(getActivity().getApplicationContext(), NB.class);
            TabHost.TabSpec tabSpecNB = tabHost.newTabSpec("NB");
            tabSpecNB.setIndicator("", resources.getDrawable(R.drawable.netb));
            tabSpecNB.setContent(netbintent);

            Intent ccardintent = new Intent(getActivity().getApplicationContext(), Cc.class);
            TabHost.TabSpec tabSpecCc = tabHost.newTabSpec("CC");
            tabSpecCc.setIndicator("", resources.getDrawable(R.drawable.cc));
            tabSpecCc.setContent(ccardintent);


            tabHost.addTab(tabSpecNB);
            tabHost.addTab(tabSpecCc);
        } catch(Exception e) {
            AlertDialog.Builder ad = new AlertDialog.Builder(getActivity().getApplicationContext());
            ad.setMessage(e.toString());
            ad.show();
        }

        return mRoot;
    }
}
Ziem
  • 6,579
  • 8
  • 53
  • 86
devcodes
  • 1,038
  • 19
  • 38
  • did you find an answer to your problem? – Shourya Sharma May 28 '15 at 14:53
  • nah , i was in a bit of hurry to complete the project , just changed the layout -_- , used simple tabbed layout instead of fragment Will surely try it out and post answer as soon as i get it :) – devcodes May 28 '15 at 17:55

2 Answers2

0

Sounds like you need to use FragmentTabHost inside your "bottom" fragment.

Another link that could help you out here.

Also, it seems on only work in API 17 and above, so be sure to keep that in mind!

Noel Bautista
  • 175
  • 1
  • 12
0

I will not recommend FragmentTabHost its somehow difficult to use and don't have swipe Left-Right. TabHostActivity is also deprecated, use SlidingTabLayout its open source and easily to use and update and have swipe.

SlidingTabLayout

Haris Qurashi
  • 2,104
  • 1
  • 13
  • 28