1

I am trying to use add a list view in ne of the tab in tabbed template in android studio. For that I am also using fragment(list) template. But I am not able to connect these two.

On creating fragment(list) template. I got the below files. MyItemRecyclerViewAdapter.java, ItemFragment.java, fragment_item.xml, fragment_itemm_list.xml

I updated the oncreateView for tabbing as below.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
    if (getArguments().getInt(ARG_SECTION_NUMBER) == 3) {
        View rootView = inflater.inflate(R.layout.fragment_item, container, false);
        return rootView;
    }
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    TextView textView = (TextView) rootView.findViewById(R.id.section_label);
    textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
    return rootView;
}

But I am not getting anything i.e getting empty page on the third tab.

tarun14110
  • 940
  • 5
  • 26
  • 57
  • @cricket_007, that I did managed. As I am just using simple texts on those. I am getting right on those tabs. Updated. – tarun14110 Oct 11 '16 at 20:00
  • `fragment_item.xml` looks like what? – OneCricketeer Oct 11 '16 at 20:04
  • I think you really should be using a `ViewPager`, which is attached to the `TabLayout`, which displays Fragments with a `FragmentPagerAdapter`. It is unclear why you are conditionally loading different Fragment layouts from one class. – OneCricketeer Oct 11 '16 at 20:05
  • oh sorry, that was typo, while writing question. updated. – tarun14110 Oct 11 '16 at 20:05
  • I was just learning to use tabLayout. So, I just read this way to return different view for each tab. Am I doing wrong or not in good way ? – tarun14110 Oct 11 '16 at 20:08
  • TabLayout is good, but in order to "hook" fragments to it, I believe a ViewPager is the recommended approach. [TabLayout documentation](https://developer.android.com/reference/android/support/design/widget/TabLayout.html) and [tutorial](https://github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-TabLayout) – OneCricketeer Oct 11 '16 at 20:18
  • This might help, it has a complete solution that uses a RecyclerView, which is the replacement of ListView: http://stackoverflow.com/questions/34579614/how-to-implement-recyclerview-in-a-fragment-with-tablayout – Daniel Nugent Oct 11 '16 at 21:13
  • try these tutorials http://www.androidhive.info/2012/05/android-combining-tab-layout-and-list-view/ https://www.youtube.com/watch?v=D2mMwWiZBmE – Akash Raghav Oct 12 '16 at 05:14

0 Answers0