Gridview Pagination - Sketchware

Gridview Pagination


 Here is the codes for make Pagination for GridView in Sketchware..

So we can load data faster from Firebase DB

And make the app more efficient..

CODES :👇


On create :


1.

query = dplay.limitToLast((int)limit);
query.addValueEventListener(valueEventListener1);

The underlined part of above code is my firebase database component name replace it with your db component name.. 

2.

}
com.google.firebase.database.Query query;

3.

ValueEventListener valueEventListener1 = new ValueEventListener() {
@Override public void onDataChange(DataSnapshot _param1) {
try {
str ="";
listmap.clear();
GenericTypeIndicator < HashMap< String, Object>> _ind = new GenericTypeIndicator<HashMap< String, Object>>() {};

for (DataSnapshot _data : _param1.getChildren()) {
str = (_data.getKey());
HashMap <String, Object> _map= _data.getValue(_ind);
listmap.add(_map);
}

4 .(inside timer component)

GridView grids = (GridView) findViewById(R.id.grid);
((BaseAdapter)grids.getAdapter()).notifyDataSetChanged();

5.

} catch (Exception e) { showMessage(e.toString()); } }
@Override public void onCancelled(DatabaseError databaseError) { } }; {




OnPostCreate :


6.

GridView grids = (GridView) findViewById(R.id.grid);
((ViewGroup)grid.getParent()).removeView(grid);
grid.setLayoutParams(new GridView.LayoutParams(GridLayout.LayoutParams.MATCH_PARENT, GridLayout.LayoutParams.WRAP_CONTENT)); grid.setNumColumns(3); grid.setColumnWidth(GridView.AUTO_FIT); grid.setBackgroundColor(0xFFFFFF); grid.setVerticalSpacing(5); grid.setHorizontalSpacing(5); grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); grid.setVerticalScrollBarEnabled(false);


In above code the underlined part.. is the background color of GRIDVIEW.. you can change it as per your need..

7.

grid.setAdapter(new Listview1Adapter(listmap));
linear1.addView(grid);




On Loadmore Click (textview1)


8.

query = dplay.limitToLast((int)limit);

query.addValueEventListener(valueEventListener1);

Replace the "dplay" with your firebase 🔥 component name


If you have any questions please feel free to comment below..

LIKE SHARE SUPPORT 🥰