Sergio76
Sergio76

Reputation: 3986

Loading data from FragmentActivity

I'm using a FragmentActivity type activity, contains three activities:

adapter.addFragment(new activityOne());
adapter.addFragment(new activityTwo());
adapter.addFragment(new activityThree());

Each of these activities have a listview that reads data from internet. the problem is that when I launch the main activity, which extends FragmentActivity, loads the contents of the three activities, when I'm trying to do is to load the data for each activity only when it is shown on the screen.

I used setOnPageChangeListener, but the solution is not there

Any help is greatly appreciated.

Regards

Upvotes: 0

Views: 321

Answers (1)

Nags
Nags

Reputation: 31

I had the similar problem and solved it. What you can do is, keep a public method on those Fragement classes that will have the code to load the data. Call that method from the main FragmentActivity's OnPageChangeListener() inside the onPageSelected() method. In this way you can load the data when that particular page is viewed by the user.

Upvotes: 1

Related Questions