0

I am learning Android/Java and I'm not sure how to convey to Google what I want to do.

I need help in understanding how to take once piece of data show it on different tabs.

For example I have a JSON object that contains a "Student". This object holds everything, Student Identity, Grades, Current Classes, Lunch Money.

After I select a student from a list view, I want to show each of the sub-objects on different tabs.

I can get my data from the JSON Object, I can even show the data and refresh it in my MasterViewActivity.

enter image description here

How can I add tabs to this activity? More importantly, how do I notify and update the tabs with the new information when the refresh has been pressed?

I have looked at this SO question, and this but I don't think it helped. I have Googled tutorials, but a lot of them are all different, some use multiple activities- some use fragments. None that I have encountered have given an indication of how to notify/update the various tabs that data has changed.

I am hoping someone has a link to a good tutorial that would fit with what I am trying to do. Or possibly has some code snippets they are willing to share to help get me started.

I would prefer to do this without the user of external frameworks or github repos.

Community
  • 1
  • 1
user-44651
  • 3,924
  • 6
  • 41
  • 87
  • First tell me what is refresh button for? My point of view is that when you click on a student in list, a new view(Activity or fragment) shows up and shows the information of student. so the question is what is that refresh button for? – M. Erfan Mowlaei Nov 15 '16 at 16:25
  • @ErfanMowlaei I need to re-query the database when I am in record to check for changes. Instead of leaving the view and re-selecting an item from the list. – user-44651 Nov 15 '16 at 16:27

1 Answers1

0

Okay, As for selection between activity or fragment, it totally depends on your decision based on situation you are in, however using fragment is probably advised one vs creating new activity which is supposed to be easier. For tabs you need a TabLayout which is fed like this:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    adapter = new ModuleBasedFragmentPagerItemAdapter(getChildFragmentManager(),
            Locale.getDefault(),
            ModuleHelper.getInstance().getFragmentList(getContext(), fragmentType));



    viewPager = (CustomViewPager) view.findViewById(R.id.viewpager);
    viewPager.setAdapter(adapter);

    viewPagerTab = (SmartTabLayout) view.findViewById(R.id.viewPagerTab);
    viewPagerTab.setViewPager(viewPager);

}

So you need a ViewPager and FragmentStatePagerAdapter to populate it and here in the code I have used SmartTabLayout Libray, you can use native TabLayout too. you can give different params to FragmentStatePagerAdapter in order to initilize it's tabs and fragments which are produced per tab.

This way you can create what you asked for.

M. Erfan Mowlaei
  • 1,376
  • 1
  • 14
  • 25