Can't call fragment method from activity - android

I have activity, that contains viewpager, with some fragment on the each tab. I want to call some method from fragment. I'm using:
android.support.v4.app.Fragment;
My code:
Main Activity:
public class ProfileActivity extends BaseTabsActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
initTabs();
// call method here
}
}
public class BaseTabsActivity extends BaseActivity {
protected void initTabs() {
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setOffscreenPageLimit(4);
mViewPager.setAdapter(new ProfileTabsAdapter(getSupportFragmentManager(), this));
}
}
ProfileTabsAdapter:
public class ProfileTabsAdapter extends FragmentPagerAdapter {
public ProfileTabsAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 0:
return new Fragment0();
case 1:
return new Fragment1();
case 2:
return new Fragment2();
case 3:
return new Fragment3();
case 4:
return new Fragment4();
}
return null;
}
#Override
public int getCount() {
return 5;
}
#Override
public CharSequence getPageTitle(int index) {
switch (index) {
case 0:
return context.getResources().getString(R.string.string0);
case 1:
return context.getResources().getString(R.string.string1);
case 2:
return context.getResources().getString(R.string.string2);
case 3:
return context.getResources().getString(R.string.string3);
case 4:
return context.getResources().getString(R.string.string4);
}
return null;
}
}
Fragment:
public class Fragment0 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment, container, false);
return rootView;
}
public String doSomething() {
return "hi";
}
}
Have any idea?

It's well described in the official documentation: https://developer.android.com/training/basics/fragments/communicating.html
For your convinience, here is relevant part of the code:
ArticleFragment articleFrag = (ArticleFragment)
getSupportFragmentManager().findFragmentById(R.id.article_fragment);
if (articleFrag != null) {
// If article frag is available, we're in two-pane layout...
// Call a method in the ArticleFragment to update its content
articleFrag.updateArticleView(position);
}
But please make sure and go read the docs I linked at the begining.

Related

Passing data from recyclerview adapter of activity-1 to viewpager fragment of activity-2

my recyclerView Adapter - Activity-1
here i'm sending arguments to ViewPager Fragmnet using setArguments()
#Override
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString("projectName", jobCardLists.get(position).getProject());
// set MyFragment Arguments
DetailsFragment detailsFragment = new DetailsFragment();
detailsFragment.setArguments(bundle);
Intent intent = new Intent(context, JobCardViewActivity.class);
context.startActivity(intent);
});
}
Activity-2 which contains ViewPager - Tab layout
public class JobCardViewActivity extends AppCompatActivity {
private ViewPager mViewPager;
private Toolbar mToolbar;
private JobCardViewVPAdapter mViewPagerAdapter;
private TabLayout mTabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_job_card_view);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
//set TabLayout
setViewPager();
}
private void setViewPager() {
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPagerAdapter = new JobCardViewVPAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mViewPagerAdapter);
mTabLayout = (TabLayout) findViewById(R.id.tab);
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.getTabAt(0).setIcon(R.drawable.ic_home_white_24dp);
}
}
My viewPager Adapter
public class JobCardViewVPAdapter extends FragmentStatePagerAdapter {
private static int TAB_COUNT = 6;
public JobCardViewVPAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return DetailsFragment.newInstance();
case 1:
return WorkActivitiesFragment.newInstance();
case 2:
return DocumentsFragment.newInstance();
case 3:
return TasksFragment.newInstance();
case 4:
return WorkImagesFragment.newInstance();
case 5:
return NotesFragment.newInstance();
}
return null;
}
#Override
public int getCount() {
return TAB_COUNT;
}
#Nullable
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 1:
return WorkActivitiesFragment.TITLE;
case 2:
return DocumentsFragment.TITLE;
case 3:
return TasksFragment.TITLE;
case 4:
return WorkImagesFragment.TITLE;
case 5:
return NotesFragment.TITLE;
}
return super.getPageTitle(position);
}
}
My ViewPager fragment class
here i'm getting NULL from getArguments()
public class DetailsFragment extends Fragment {
private View view;
private Activity activity;
public static final String TITLE = "Details";
private String projectName;
public DetailsFragment() {
// Required empty public constructor
}
public static DetailsFragment newInstance() {
return new DetailsFragment();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = getActivity();
if (getArguments() != null) {
Bundle bundle = getArguments();
projectName = bundle.getString("projectName");
} else {
Toast.makeText(activity, "NULL", Toast.LENGTH_SHORT).show();
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_details, container, false);
TextView tvProjectName, startDate, endDate, assignedBy, workCategory, status;
tvProjectName = view.findViewById(R.id.tv_project_name);
tvProjectName.setText(projectName);
return view;
}
1.You can use Single Object (singleton) for your fragment.
In your fragment use,
private static DetailsFragment ourInstance = new DetailsFragment();
public static DetailsFragment newInstance() {
return ourInstance;
}
And in your onBindViewHolder(), use
DetailsFragment detailsFragment = DetailsFragment.newInstance();
detailsFragment.setArguments(bundle);
2.Or else, pass data between the activities
In your onBindViewHolder(), use
Intent intent = new Intent(context, JobCardViewActivity.class);
intent.putString("project", jobCardLists.get(position).getProject());
context.startActivity(intent);
and do,
1.in JobCardViewActivity,get the string and save it
myString=getIntent().getString("project"); //public String myString;
2.in fragment, use that saved string
tvProjectName.setText(((JobCardViewActivity)getActivity()).myString);

6 Fragments hided/shown by ViewPager without being dismissed

I have 6 Fragments within an activity that I created as
I want to swipe from one to the other and need them to not being dismissed but onyl hide/show y the viewpager.
Is there a way to derive a viewpager class or a SectionsPagerAdapter to do that.
I already add
mViewPager.setOffscreenPageLimit(6);
but it didn't work. When swiping from the 4th fragment to 3rd or to 5th, the app crashes.
Relevant parts of my code simpified and renamed Fragment classes to get the code readable:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// create the fragment once for all !
if (savedInstanceState == null) {
fragment1 = Fragment1.newInstance(1);
fragment2 = Fragment2.newInstance(2);
fragment3 = Fragment3.newInstance(3);
fragment4 = Fragment4.newInstance(4);
fragment5 = Fragment5.newInstance(5);
fragment6 = Fragment6.newInstance(6);
}
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(6);
});
public static class Fragment1 extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public Fragment1() {
}
public static Fragment1 newInstance(int sectionNumber) {
Fragment1fragment = new Fragment1();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
fragment.setRetainInstance( true);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_1, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
// "Main Frag"
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
#Override
public void onResume() {
super.onResume();
// The activity is about to become visible again, recalcule
}
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
//return PlaceholderFragment.newInstance(position + 1);
switch (position)
{
case 0 : return fragment1; //instead of Fragment1.newInstance(1);
case 1 : return fragment2;
case 2 : return fragment3;
case 3 : return fragment4;
case 4 : return fragment5;
case 5 : return fragment6;
default: return null;
}
}
#Override
public int getCount() {
// Show 6 total pages.
return 6;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
case 2:
return "SECTION 3";
case 3:
return "SECTION 4";
case 4:
return "SECTION 5";
case 5:
return "SECTION 6";
}
return null;
}
}
Extend your section pager adapter by FragmentSatePagerAdaper
And set
mViewPager.setOffscreenPageLimit(6);

Viewpager does not inflate the fragments having already inflated another view pager

I have a project that needs to have two viewpager, each in a different fragment of the activity.
The architecture something like this
The problem is that when a pager view is inflated, the other isn't.
For example, the fragments 1, 2 and 3 can be accessed by clicking. When I click on the first fragment, it inflates the view pager with its two fragments perfectly, but if I click on the fragment 3, the view pager does not inflate the fragments and also the tabs get slower.
Opening the application process again, by clicking on the fragment 3 first, it works perfectly, but clicking on the first after, this problem happens again.
Already debugged the processes and there is nothing different.
My Activity
public class HomeActivity extends AppCompatActivity implements NavigationFragment.OnNavigationListener{
public NavigationFragment mNavigation;
private String mTagFragmentShowing = "";
private int currentNavigation = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
mNavigation = (NavigationFragment) getFragmentManager().findFragmentById(R.id.manager_navigation);
onNavigationSelected(currentNavigation);
}
#Override
public void onNavigationSelected(int position) {
if (mTagFragmentShowing.equals(String.valueOf(position)))
return;
currentNavigation = position;
mNavigation.setNavigationSelected(position);
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(mTagFragmentShowing);
// Hide last fragment
if (fragment != null && fragment.isVisible()) {
fragmentManager.beginTransaction().hide(fragment).commit();
}
// Show new fragment
mTagFragmentShowing = String.valueOf(position);
fragment = fragmentManager.findFragmentByTag(mTagFragmentShowing);
if (fragment != null && fragment.isHidden()) {
fragmentManager.beginTransaction().show(fragment).commit();
} else if (fragment == null) {
fragmentManager.beginTransaction().add(R.id.manager_content, getFragmentByPosition(position), mTagFragmentShowing)
.setTransition(FragmentTransaction.TRANSIT_NONE).commit();
}
}
private Fragment getFragmentByPosition(int position) {
switch (position) {
case 0:
return new DiscoverFragment();
case 1:
return new UpcomingFragment();
case 2:
return new FeaturesFragment();
case 3:
return new VideosFragment();
case 4:
return new MySongsFragment();
}
return null;
}
My Navigation Fragment. It control the other fragments
public class NavigationFragment extends Fragment implements View.OnClickListener {
public ViewHolder mHolder;
public View mButtonSelected;
public OnNavigationListener mCallback;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.component_navigation, container, false);
ButterKnife.bind(this, view);
initView(view);
return view;
}
public void initView(View view) {
mHolder = new ViewHolder();
mHolder.discover = view.findViewById(R.id.component_navigation_discover);
mHolder.upcoming = view.findViewById(R.id.component_navigation_upcoming);
mHolder.features = view.findViewById(R.id.component_navigation_features);
mHolder.videos = view.findViewById(R.id.component_navigation_videos);
mHolder.mymusic = view.findViewById(R.id.component_navigation_mymusic);
mHolder.discover.setTag(0);
mHolder.upcoming.setTag(1);
mHolder.features.setTag(2);
mHolder.videos.setTag(3);
mHolder.mymusic.setTag(4);
mHolder.discover.setOnClickListener(this);
mHolder.upcoming.setOnClickListener(this);
mHolder.features.setOnClickListener(this);
mHolder.videos.setOnClickListener(this);
mHolder.mymusic.setOnClickListener(this);
mButtonSelected = mHolder.features;
}
public void setNavigationSelected(int position) {
setNavigationButtonSelected(false);
switch (position) {
case 0:
mButtonSelected = mHolder.discover;
break;
case 1:
mButtonSelected = mHolder.upcoming;
break;
case 2:
mButtonSelected = mHolder.features;
break;
case 3:
mButtonSelected = mHolder.videos;
break;
case 4:
mButtonSelected = mHolder.mymusic;
break;
}
setNavigationButtonSelected(true);
}
public void setNavigationButtonSelected(boolean enabled) {
mButtonSelected.setBackgroundColor(enabled ? getResources().getColor(R.color.color_red) : Color.TRANSPARENT);
}
#Override
public void onClick(View view) {
if (view != mButtonSelected) {
mCallback.onNavigationSelected((Integer) view.getTag());
}
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnNavigationListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnNavigationSelectedListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mCallback = null;
}
static class ViewHolder {
View discover;
View upcoming;
View features;
View videos;
View mymusic;
}
public interface OnNavigationListener {
public void onNavigationSelected(int position);
}
My Fragments with View Pager
public class MySongsFragment extends Fragment {
private OnFragmentInteractionListener mListener;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.mysongs_fragment_container, MySongsViewPagerFragment.newInstance(0)).commit();
return inflater.inflate(R.layout.fragment_my_songs, container, false);
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}
My View Pager
public class MySongsViewPagerFragment extends Fragment {
private static final int NUM_PAGES = 4;
private String[] tab_names;
private List<String> mTabNames;
private PagerAdapter mPagerAdapter;
public #Bind(R.id.pager)
ViewPager mPager;
public static MySongsViewPagerFragment newInstance(int index) {
MySongsViewPagerFragment fragment = new MySongsViewPagerFragment();
Bundle args = new Bundle();
args.putInt("index", index);
fragment.setArguments(args);
return fragment;
}
#Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = initView(inflater, container);
return view;
}
#NonNull private View initView(LayoutInflater inflater, ViewGroup container) {
View view = inflater.inflate(R.layout.fragment_view_pager_my_songs, container, false);
ButterKnife.bind(this, view);
tab_names = getResources().getStringArray(R.array.tabs_mysongs);
mTabNames = Arrays.asList(tab_names);
mPagerAdapter = new ScreenSlidePagerAdapter(getActivity().getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
mPager.onTouchEvent(event);
return false;
}
});
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mPager);
return view;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
#Override public Fragment getItem(int position) {
switch (position) {
case 0:
return new PlaylistsFragment();
case 1:
return new SongsFragment();
case 2:
return new AlbumsFragment();
case 3:
return new ArtistsFragment();
default:
return new PlaylistsFragment();
}
}
#Override public int getCount() {
return NUM_PAGES;
}
#Override public CharSequence getPageTitle(int position) {
return mTabNames.get(position);
}
}
The problem was activity context in viewpager
In My View Pagers. I change
mPagerAdapter = new ScreenSlidePagerAdapter(getActivity().getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
to
mPagerAdapter = new ScreenSlidePagerAdapter(getChildFragmentManager());
mPager.setAdapter(mPagerAdapter);
The two viewpager used the same context. So when I inflated the first, the other was not inflated because interpreted that already existed an inflated viewpager.
Thanks for the help mcwise for show me the method getChildFragmentManager().

How to implement swipe view on fragment

I'm trying to implement a swipe inside a fragment! My application use a Navigation Drawer Layout and I change view with the drawer. All the view that I show are fragment. Now, I want to implement into a specific fragment an horizontal swipe. How can I do this thing? my code is here :
public class MybookingFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
final View Rootview = inflater.inflate(R.layout.mybooking, parent, false);
ViewPager viewPager = (ViewPager) Rootview.findViewById(R.id.viewpager);
FragmentManager fragmentManager = getChildFragmentManager();
viewPager.setAdapter(new SlidingPagerAdapter(fragmentManager));
return Rootview;
}
my adapter code is here
public class SlidingPagerAdapter extends FragmentStatePagerAdapter {
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
public SlidingPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
Class fragmentClass = null;
switch (position) {
case 0:
fragmentClass = UpcomingOrder.class;
case 1:
fragmentClass = RunningOrder.class;
break;
case 2:
fragmentClass = CompletedOrder.class;
break;
default:
fragmentClass = UpcomingOrder.class;
break;
}
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return fragment;
}
#Override
public int getCount() {
// For this contrived example, we have a 100-object collection.
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
}
Try this below example. I think you are asking this only
Example 1
Example 2
Tabs swipe
You have to use main fragment. with in that fragment you have to load all sub-fragments(tabs).

When to update information for ViewPager?

If I ave an activity with a viewPAger on it and two sets of data that I want to display, is it best to have one fragment and load information into textViews based on position passed from activity or better to create more than one fragment and load the one needed?
Any help is greatly appreciated.
public class testFragment extends Fragment {
private static final String ARG_PAGE = "pageNumber";
private static final int DEFAULT_INT = 0;
TextView header, sd1;
int h1, page = 0;
public testFragment (){
}
public testFragment newInstance(int pageNumber) {
testFragment fragment = new testFragment ();
Bundle args = new Bundle();
args.putInt(ARG_PAGE, pageNumber);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
page = getArguments().getInt(ARG_PAGE);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_high_scores_page, container, false);
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
header = (TextView) getActivity().findViewById(R.id.modes_header);
sd1 = (TextView) getActivity().findViewById(R.id.stat_det_1);
switch (page) {
case 1:
header.setText(R.string.easy_mode);
h1 = DEFAULT_INT;
sh1 = DEFAULT_INT;
sd1.setText(String.valueOf(h1));
break;
case 2:
header.setText(R.string.medium_mode);
h1 = DEFAULT_INT + 1;
sh1 = DEFAULT_INT + 1;
sd1.setText(String.valueOf(h1));
break;
default:
header.setText(R.string.action_restart);
h1 = DEFAULT_INT;
sh1 = DEFAULT_INT;
sd1.setText(String.valueOf(h1));
break;
}
}
public void setTextViewInfo(){
sd1.setText(String.valueOf(h1));
}
}
Or would it be better to send the information from my activity and load one or multiple fragments instead?
public class testActivity extends FragmentActivity {
private static final int NUM_PAGES = 8;
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testActivity);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.high_scores_pager);
mPagerAdapter = new testActivity (getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
#Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
super.onBackPressed();
} else {
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
}
private class testActivityAdapter extends FragmentStatePagerAdapter {
public testActivityAdapter (FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
testFragment tf1 = new testFragment ();
notifyDataSetChanged();
return easy.newInstance(position);
case 1:
testFragment2 tf2 = new testFragment ();
notifyDataSetChanged();
return medium.newInstance(position);
default:
testFragment d = new testFragment ();
return d.newInstance();
}
}
#Override
public int getItemPosition(Object object) {
return super.getItemPosition(object);
}
#Override
public int getCount() {
return NUM_PAGES;
}
}
}
edit:
In my adapter, I just tried
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return HighScoresEasyFragment.newInstance(position);
case 1:
return HighScoresMediumFragment.newInstance(position);
case 2:
return HighScoresExpertFragment.newInstance(position);
case 3:
return HighScoresBrainFartFragment.newInstance(position);
case 4:
return HighScoresClassicFragment.newInstance(position);
case 5:
return HighScoresPuzzleFragment.newInstance(position);
case 6:
return HighScoresPerfectFragment.newInstance(position);
case 7:
return HighScoresPowerFragment.newInstance(position);
default:
return HighScoresEasyFragment.newInstance(position);
}
ugh, but it didn't load anything... my constructor is now...:
public static HighScoresEasyFragment newInstance(int pageNumber) {
HighScoresEasyFragment fragment = new HighScoresEasyFragment();
Bundle args = new Bundle();
args.putInt(ARG_PAGE, pageNumber);
fragment.setArguments(args);
return fragment;
}
It loaded the first page's header but no data and it didn't load anything for second to 8th fragments...
You should call notifyDataChanged() from your activity using your adapter reference. Basically notifyDataChanged just tells all your fragments in your adapter that data has changed and they should refresh themselves. Remove notifyDataChanged from your getItem() method and put it when you change data in your activity.

Categories

Resources