I have a backend API endpoint which returns JSON
in some sets. Each set contain 10 lines of Json
.
For example:
curl http://www.something.com?getData=0
will give first 10 elements
and curl http://www.something.com?getData=1
will return next set and so on.
I am using RecyclerView
and StaggeredGridView
to load data from given endpoints
. Right now I am only fetching first set and it's working perfectly fine.
What I am looking for?
How can I load data in RecyclerView
as per screen sizes in Android
. FOr example:
Let's say device hdpi
can able to load 25 staggeredGridView
in RecyclerView
. So , here the endpoints
request in sequence:
http://www.something.com?getData=0 // will fetch 0-10
http://www.something.com?getData=10 // will fetch 11-20
http://www.something.com?getData=10&skip=5 // will fetch 21-25
How can I make above process dynamically. So that it will work for all screen sizes?
BTW this is how I am loading the data into StaggeredGridView
adapter:
mRecyclerView = (RecyclerView) mActivity.findViewById(R.id.staggering_grid);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mAdapter = new StaggeredGridAdapter(mContext);
mAdapter.addItems(response);
mRecyclerView.setAdapter(mAdapter);
Possible Solution
- If I got to know that How much
Grid
I need to fill according to device then I can simply make a request till I get the data to fill expected number. - I can also use
Event Bus
to send notification toRetrofit
to make another call till device screen filled.
Is it good approach? If yes then How can I achieve it?
RecyclerView
withStaggeredGridView
adapter – Gui