emir
emir

Reputation: 1406

One or more fragments containing listview with tabs?

I have used Android Studio example with tabs and fragment, but I have some different idea. I need to automatically generate tabs and fragments, which will contain listview and will be populated using JSON.

I am successfully fetching data from JSON and placing them in one activity, but my intention is to use tabs which will serve as categories, so each time I click on different category it will show different news. My intention is that first time user clicks on tab/category, app should populate it with news, and next time he gets back it will not reload, it will show what is loaded before unless he wants to refresh it.

Refreshing category should be done by pulling down.

So, should I use one fragment as template, as all news will be presented the same way and populate it with data, or will I need to create fragment for each category?

If I will need to create different fragments for each, then in order to add new category I would need to update app version.

Upvotes: 0

Views: 46

Answers (2)

Safal Kumar Ghimire
Safal Kumar Ghimire

Reputation: 318

Why dont you use pull to refresh on each tab fragment. And apply the condition, if pull to refresh then load new contents or refresh the data... or else display the old data as it is. Hope it helps you!

Upvotes: 1

kasar sandeep
kasar sandeep

Reputation: 46

No need to create different fragment for each category. Just change the adapter content as you load data from server. But data for each category must be same ,means json object must have same keys in all categories. Otherwise use different fragments for each category of news.

Upvotes: 1

Related Questions