vikas devde
vikas devde

Reputation: 11751

How to prevent off-screen pages of ViewPager from loading content when Activity is started?

I have 3 tabs in MainActivity, which loads the content in ViewPager. But when the activity starts it loads the contents of second tab also which is off-screen. My tabs are like received message and sent message, and when there are no messages in any, I am showing a Toast that "There are no messages". SO now when the activity starts the default tab "Received" has the messages but still a Toast is shown because there are no "Sent" messages in the second tab.

I want the content of second tab to be loaded only when user selects it.

Upvotes: 0

Views: 266

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

But when the activity starts it loads the contents of second tab also which is off-screen

ViewPager immediately loads additional pages, with an eye towards being able to animate between pages. You cannot prevent ViewPager from loading additional pages.

when there are no messages in any, I am showing a Toast that "There are no messages"

Get rid of the Toast and have some inline UI in the tabs ("empty view") that indicates that there are no messages in that tab.

Upvotes: 1

Related Questions