I am a bit confused. I am working on a newsstand app in Android. I have 20 categories. When a user click any tabs, app will show news about tab title and when app is open, app will load all news related to all categories. Should I have to create 20 models and RecyclerViews or can I do that with one model and RecyclerView? And how to do without refreshing adapter and model. I will be glad if you help. Thanks :)
Asked
Active
Viewed 101 times
1 Answers
1
You can use a single model with different case sets such that you get the adapter data switched based on the category if the data models in the categories (multiple) remains the same model wise.
case Category 1:
//based on the api data
setadapter
case Category 2:
//based on the api data
setadapter
......
Hope this gives a rough idea

Shadab K
- 1,677
- 1
- 16
- 25
-
but app loads all data from different categories at the same time, don't I need to use different Adapters? – nuhkoca Jul 03 '16 at 16:11
-
Is the app having tab based layouts like the newsstand app? If yes, then you should load it when the specific category is in focus and release the previous data set for best performance and user experience. – Shadab K Jul 03 '16 at 17:02
-
yes, it is tabbed layout. If I do like you said I need to load data which fragment is focused, dont I? If user go back to previous tab I need to consume JSON again and it needs an internet, dont I? Thanks – nuhkoca Jul 03 '16 at 17:05
-
In your each fragment put a call to async task and call it based on the position of the tablayout from your base activity w.r.t. Tab View Pager selected Use this method set, it works like a charm. https://developer.android.com/reference/android/support/design/widget/TabLayout.ViewPagerOnTabSelectedListener.html And yes to keep the user updated you need to use internet. – Shadab K Jul 03 '16 at 17:49
-
@Nuh Koca If I have answered your query mark the answered – Shadab K Jul 03 '16 at 19:09
-
yeah I am gonna but I already have this idea. Actually I want to set all data related to its own category to recyclerview and show them at the same time. Do I have to release recyclerview for the previous ones? For instance Google News shows all news at the same time but how? – nuhkoca Jul 04 '16 at 01:13
-
It iscompletely the way you would like to showcase the data, – Shadab K Jul 04 '16 at 07:37
-
You can use single recycler view with all the data like google news or you can use the tabbed layout with database support ( not advisable to use database in terms of news app ) like the play newsstand app. If you release the recycler view you can repopulate it if the data is refrehed on the next instance of that recycler view, else you will need the user to wait for a while untill the data clears and then repopulate it again.. therefore bad user experince as per my point of view – Shadab K Jul 04 '16 at 07:42
-
Okay, I'll do it like you said, thanks for help and idea, I've marked your reply as answered. – nuhkoca Jul 04 '16 at 15:20