android Firebase Realtime database Query combinig orderbychild() with Start()
My database looks like this
What I want to do is I want to load first 6 item followed by next 5 item using below code
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(15);
if(!LastPostKey.equals(Lastmostkey))
noticeDatas.clear();
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
But nothing is showing up when I click loadmoredata button
Here is the full code
package com.nadim.csedashboard;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.messaging.FirebaseMessaging;
import com.nadim.csedashboard.adapters.NoticeAdapter;
import com.nadim.csedashboard.dataset.NoticeData;
import java.util.ArrayList;
import java.util.List;
public class DashBoardActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
String username = "";
String LastPostKey = "", Lastmostkey = "";
List<NoticeData> noticeDatas = new ArrayList<>();
NoticeAdapter noticeAdapter;
final int item = 5;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
new InternetCheck(new InternetCheck.Consumer()
@Override
public void accept(Boolean internet)
if(internet)
FirebaseMessaging.getInstance().subscribeToTopic("notice").addOnSuccessListener(new OnSuccessListener<Void>()
@Override
public void onSuccess(Void aVoid)
Toast.makeText(getApplicationContext(),"subs to notice Success",Toast.LENGTH_LONG).show();
);
Toast.makeText(DashBoardActivity.this,"Internet Found", Toast.LENGTH_LONG).show();
else
Toast.makeText(DashBoardActivity.this,"Internet not Found", Toast.LENGTH_LONG).show();
);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null)
username = "SignOut ("+user.getEmail()+")";
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView listViewnotice = findViewById(R.id.listView_notice);
DatabaseReference noticeRef = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRef.orderByChild("timestamp").limitToFirst(6);
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
//Toast.makeText(DashBoardActivity.this,"Current Key:"+LastPostKey,Toast.LENGTH_LONG).show();
Log.d("texting","current Key: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
Query lastKey = noticeRef.orderByKey().limitToFirst(1);
lastKey.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
Lastmostkey = dataSnapshot.getKey();
Log.d("texting","Last Key: "+ Lastmostkey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
noticeAdapter = new NoticeAdapter(this,noticeDatas);
listViewnotice.setAdapter(noticeAdapter);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View loadMore = inflater.inflate(R.layout.more, null);
listViewnotice.addFooterView(loadMore);
Button loadmoredata = loadMore.findViewById(R.id.button_loadmore);
loadmoredata.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("texting","this but is working inside"+ noticeDatas.size());
Log.d("texting","current Key after click: "+ LastPostKey);
Log.d("texting","last Key after click: "+ Lastmostkey);
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(noticeDatas.size() + 5 );
if(!LastPostKey.equals(Lastmostkey))
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
);
listViewnotice.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(DashBoardActivity.this,NoticeActivity.class);
intent.putExtra("dlimage",noticeDatas.get(i).getNotice_picture());
intent.putExtra("ntitle",noticeDatas.get(i).getNoticetitle());
startActivity(intent);
);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent svc = new Intent(DashBoardActivity.this, ViewClass.class);
svc.putExtra("batchname","8thBatch");
//startService(svc);
startActivity(svc);
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
@Override
public void onBackPressed()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else
finishAffinity();
System.exit(0);
@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dash_board, menu);
return true;
@Override
public boolean onPrepareOptionsMenu(Menu menu)
menu.findItem(R.id.action_logout).setTitle(username);
return super.onPrepareOptionsMenu(menu);
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
Intent intent = new Intent(DashBoardActivity.this,UserProfile.class);
startActivity(intent);
return true;
if (id == R.id.action_logout)
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(DashBoardActivity.this,LoginActivity.class);
startActivity(intent);
Toast.makeText(DashBoardActivity.this, "Signed Out.",
Toast.LENGTH_LONG).show();
return true;
if (id == R.id.action_back)
onBackPressed();
return true;
return super.onOptionsItemSelected(item);
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera)
// Handle the camera action
else if (id == R.id.nav_gallery)
else if (id == R.id.nav_slideshow)
else if (id == R.id.nav_manage)
else if (id == R.id.nav_share)
else if (id == R.id.nav_send)
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
What should I do? Is there any way to load first 6 item followed by next 5 items? using timestamp child
java android firebase
add a comment |
My database looks like this
What I want to do is I want to load first 6 item followed by next 5 item using below code
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(15);
if(!LastPostKey.equals(Lastmostkey))
noticeDatas.clear();
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
But nothing is showing up when I click loadmoredata button
Here is the full code
package com.nadim.csedashboard;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.messaging.FirebaseMessaging;
import com.nadim.csedashboard.adapters.NoticeAdapter;
import com.nadim.csedashboard.dataset.NoticeData;
import java.util.ArrayList;
import java.util.List;
public class DashBoardActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
String username = "";
String LastPostKey = "", Lastmostkey = "";
List<NoticeData> noticeDatas = new ArrayList<>();
NoticeAdapter noticeAdapter;
final int item = 5;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
new InternetCheck(new InternetCheck.Consumer()
@Override
public void accept(Boolean internet)
if(internet)
FirebaseMessaging.getInstance().subscribeToTopic("notice").addOnSuccessListener(new OnSuccessListener<Void>()
@Override
public void onSuccess(Void aVoid)
Toast.makeText(getApplicationContext(),"subs to notice Success",Toast.LENGTH_LONG).show();
);
Toast.makeText(DashBoardActivity.this,"Internet Found", Toast.LENGTH_LONG).show();
else
Toast.makeText(DashBoardActivity.this,"Internet not Found", Toast.LENGTH_LONG).show();
);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null)
username = "SignOut ("+user.getEmail()+")";
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView listViewnotice = findViewById(R.id.listView_notice);
DatabaseReference noticeRef = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRef.orderByChild("timestamp").limitToFirst(6);
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
//Toast.makeText(DashBoardActivity.this,"Current Key:"+LastPostKey,Toast.LENGTH_LONG).show();
Log.d("texting","current Key: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
Query lastKey = noticeRef.orderByKey().limitToFirst(1);
lastKey.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
Lastmostkey = dataSnapshot.getKey();
Log.d("texting","Last Key: "+ Lastmostkey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
noticeAdapter = new NoticeAdapter(this,noticeDatas);
listViewnotice.setAdapter(noticeAdapter);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View loadMore = inflater.inflate(R.layout.more, null);
listViewnotice.addFooterView(loadMore);
Button loadmoredata = loadMore.findViewById(R.id.button_loadmore);
loadmoredata.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("texting","this but is working inside"+ noticeDatas.size());
Log.d("texting","current Key after click: "+ LastPostKey);
Log.d("texting","last Key after click: "+ Lastmostkey);
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(noticeDatas.size() + 5 );
if(!LastPostKey.equals(Lastmostkey))
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
);
listViewnotice.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(DashBoardActivity.this,NoticeActivity.class);
intent.putExtra("dlimage",noticeDatas.get(i).getNotice_picture());
intent.putExtra("ntitle",noticeDatas.get(i).getNoticetitle());
startActivity(intent);
);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent svc = new Intent(DashBoardActivity.this, ViewClass.class);
svc.putExtra("batchname","8thBatch");
//startService(svc);
startActivity(svc);
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
@Override
public void onBackPressed()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else
finishAffinity();
System.exit(0);
@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dash_board, menu);
return true;
@Override
public boolean onPrepareOptionsMenu(Menu menu)
menu.findItem(R.id.action_logout).setTitle(username);
return super.onPrepareOptionsMenu(menu);
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
Intent intent = new Intent(DashBoardActivity.this,UserProfile.class);
startActivity(intent);
return true;
if (id == R.id.action_logout)
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(DashBoardActivity.this,LoginActivity.class);
startActivity(intent);
Toast.makeText(DashBoardActivity.this, "Signed Out.",
Toast.LENGTH_LONG).show();
return true;
if (id == R.id.action_back)
onBackPressed();
return true;
return super.onOptionsItemSelected(item);
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera)
// Handle the camera action
else if (id == R.id.nav_gallery)
else if (id == R.id.nav_slideshow)
else if (id == R.id.nav_manage)
else if (id == R.id.nav_share)
else if (id == R.id.nav_send)
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
What should I do? Is there any way to load first 6 item followed by next 5 items? using timestamp child
java android firebase
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24
add a comment |
My database looks like this
What I want to do is I want to load first 6 item followed by next 5 item using below code
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(15);
if(!LastPostKey.equals(Lastmostkey))
noticeDatas.clear();
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
But nothing is showing up when I click loadmoredata button
Here is the full code
package com.nadim.csedashboard;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.messaging.FirebaseMessaging;
import com.nadim.csedashboard.adapters.NoticeAdapter;
import com.nadim.csedashboard.dataset.NoticeData;
import java.util.ArrayList;
import java.util.List;
public class DashBoardActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
String username = "";
String LastPostKey = "", Lastmostkey = "";
List<NoticeData> noticeDatas = new ArrayList<>();
NoticeAdapter noticeAdapter;
final int item = 5;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
new InternetCheck(new InternetCheck.Consumer()
@Override
public void accept(Boolean internet)
if(internet)
FirebaseMessaging.getInstance().subscribeToTopic("notice").addOnSuccessListener(new OnSuccessListener<Void>()
@Override
public void onSuccess(Void aVoid)
Toast.makeText(getApplicationContext(),"subs to notice Success",Toast.LENGTH_LONG).show();
);
Toast.makeText(DashBoardActivity.this,"Internet Found", Toast.LENGTH_LONG).show();
else
Toast.makeText(DashBoardActivity.this,"Internet not Found", Toast.LENGTH_LONG).show();
);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null)
username = "SignOut ("+user.getEmail()+")";
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView listViewnotice = findViewById(R.id.listView_notice);
DatabaseReference noticeRef = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRef.orderByChild("timestamp").limitToFirst(6);
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
//Toast.makeText(DashBoardActivity.this,"Current Key:"+LastPostKey,Toast.LENGTH_LONG).show();
Log.d("texting","current Key: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
Query lastKey = noticeRef.orderByKey().limitToFirst(1);
lastKey.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
Lastmostkey = dataSnapshot.getKey();
Log.d("texting","Last Key: "+ Lastmostkey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
noticeAdapter = new NoticeAdapter(this,noticeDatas);
listViewnotice.setAdapter(noticeAdapter);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View loadMore = inflater.inflate(R.layout.more, null);
listViewnotice.addFooterView(loadMore);
Button loadmoredata = loadMore.findViewById(R.id.button_loadmore);
loadmoredata.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("texting","this but is working inside"+ noticeDatas.size());
Log.d("texting","current Key after click: "+ LastPostKey);
Log.d("texting","last Key after click: "+ Lastmostkey);
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(noticeDatas.size() + 5 );
if(!LastPostKey.equals(Lastmostkey))
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
);
listViewnotice.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(DashBoardActivity.this,NoticeActivity.class);
intent.putExtra("dlimage",noticeDatas.get(i).getNotice_picture());
intent.putExtra("ntitle",noticeDatas.get(i).getNoticetitle());
startActivity(intent);
);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent svc = new Intent(DashBoardActivity.this, ViewClass.class);
svc.putExtra("batchname","8thBatch");
//startService(svc);
startActivity(svc);
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
@Override
public void onBackPressed()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else
finishAffinity();
System.exit(0);
@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dash_board, menu);
return true;
@Override
public boolean onPrepareOptionsMenu(Menu menu)
menu.findItem(R.id.action_logout).setTitle(username);
return super.onPrepareOptionsMenu(menu);
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
Intent intent = new Intent(DashBoardActivity.this,UserProfile.class);
startActivity(intent);
return true;
if (id == R.id.action_logout)
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(DashBoardActivity.this,LoginActivity.class);
startActivity(intent);
Toast.makeText(DashBoardActivity.this, "Signed Out.",
Toast.LENGTH_LONG).show();
return true;
if (id == R.id.action_back)
onBackPressed();
return true;
return super.onOptionsItemSelected(item);
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera)
// Handle the camera action
else if (id == R.id.nav_gallery)
else if (id == R.id.nav_slideshow)
else if (id == R.id.nav_manage)
else if (id == R.id.nav_share)
else if (id == R.id.nav_send)
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
What should I do? Is there any way to load first 6 item followed by next 5 items? using timestamp child
java android firebase
My database looks like this
What I want to do is I want to load first 6 item followed by next 5 item using below code
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(15);
if(!LastPostKey.equals(Lastmostkey))
noticeDatas.clear();
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
But nothing is showing up when I click loadmoredata button
Here is the full code
package com.nadim.csedashboard;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.messaging.FirebaseMessaging;
import com.nadim.csedashboard.adapters.NoticeAdapter;
import com.nadim.csedashboard.dataset.NoticeData;
import java.util.ArrayList;
import java.util.List;
public class DashBoardActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
String username = "";
String LastPostKey = "", Lastmostkey = "";
List<NoticeData> noticeDatas = new ArrayList<>();
NoticeAdapter noticeAdapter;
final int item = 5;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
new InternetCheck(new InternetCheck.Consumer()
@Override
public void accept(Boolean internet)
if(internet)
FirebaseMessaging.getInstance().subscribeToTopic("notice").addOnSuccessListener(new OnSuccessListener<Void>()
@Override
public void onSuccess(Void aVoid)
Toast.makeText(getApplicationContext(),"subs to notice Success",Toast.LENGTH_LONG).show();
);
Toast.makeText(DashBoardActivity.this,"Internet Found", Toast.LENGTH_LONG).show();
else
Toast.makeText(DashBoardActivity.this,"Internet not Found", Toast.LENGTH_LONG).show();
);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null)
username = "SignOut ("+user.getEmail()+")";
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView listViewnotice = findViewById(R.id.listView_notice);
DatabaseReference noticeRef = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRef.orderByChild("timestamp").limitToFirst(6);
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
//Toast.makeText(DashBoardActivity.this,"Current Key:"+LastPostKey,Toast.LENGTH_LONG).show();
Log.d("texting","current Key: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
Query lastKey = noticeRef.orderByKey().limitToFirst(1);
lastKey.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
Lastmostkey = dataSnapshot.getKey();
Log.d("texting","Last Key: "+ Lastmostkey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
noticeAdapter = new NoticeAdapter(this,noticeDatas);
listViewnotice.setAdapter(noticeAdapter);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View loadMore = inflater.inflate(R.layout.more, null);
listViewnotice.addFooterView(loadMore);
Button loadmoredata = loadMore.findViewById(R.id.button_loadmore);
loadmoredata.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("texting","this but is working inside"+ noticeDatas.size());
Log.d("texting","current Key after click: "+ LastPostKey);
Log.d("texting","last Key after click: "+ Lastmostkey);
DatabaseReference noticeRefu = FirebaseDatabase.getInstance().getReference().child("noticeboard").child("posts");
Query noticeQuery = noticeRefu.orderByChild("timestamp").startAt("-1542128676980").limitToFirst(noticeDatas.size() + 5 );
if(!LastPostKey.equals(Lastmostkey))
noticeQuery.addChildEventListener(new ChildEventListener()
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
NoticeData n = dataSnapshot.getValue(NoticeData.class);
noticeDatas.add(n);
Log.d("texting","this is working inside"+ noticeDatas.size());
noticeAdapter.notifyDataSetChanged();
LastPostKey = dataSnapshot.getKey();
Log.d("texting","current Key after Change: "+ LastPostKey);
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot)
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
else
Toast.makeText(DashBoardActivity.this,"No more notice to load",Toast.LENGTH_LONG).show();
);
listViewnotice.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Intent intent = new Intent(DashBoardActivity.this,NoticeActivity.class);
intent.putExtra("dlimage",noticeDatas.get(i).getNotice_picture());
intent.putExtra("ntitle",noticeDatas.get(i).getNoticetitle());
startActivity(intent);
);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent svc = new Intent(DashBoardActivity.this, ViewClass.class);
svc.putExtra("batchname","8thBatch");
//startService(svc);
startActivity(svc);
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
@Override
public void onBackPressed()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
else
finishAffinity();
System.exit(0);
@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dash_board, menu);
return true;
@Override
public boolean onPrepareOptionsMenu(Menu menu)
menu.findItem(R.id.action_logout).setTitle(username);
return super.onPrepareOptionsMenu(menu);
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
Intent intent = new Intent(DashBoardActivity.this,UserProfile.class);
startActivity(intent);
return true;
if (id == R.id.action_logout)
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(DashBoardActivity.this,LoginActivity.class);
startActivity(intent);
Toast.makeText(DashBoardActivity.this, "Signed Out.",
Toast.LENGTH_LONG).show();
return true;
if (id == R.id.action_back)
onBackPressed();
return true;
return super.onOptionsItemSelected(item);
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera)
// Handle the camera action
else if (id == R.id.nav_gallery)
else if (id == R.id.nav_slideshow)
else if (id == R.id.nav_manage)
else if (id == R.id.nav_share)
else if (id == R.id.nav_send)
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
What should I do? Is there any way to load first 6 item followed by next 5 items? using timestamp child
java android firebase
java android firebase
edited Nov 14 '18 at 8:36
KENdi
5,8192821
5,8192821
asked Nov 13 '18 at 20:46
smnadim21smnadim21
11
11
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24
add a comment |
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289245%2fandroid-firebase-realtime-database-query-combinig-orderbychild-with-start%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289245%2fandroid-firebase-realtime-database-query-combinig-orderbychild-with-start%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
First 6 items followed by next 5 items. Can you explain this a bit more and why not first 11 would work for you in this?
– PradyumanDixit
Nov 14 '18 at 3:55
i am making a notice Board android app in which each notice have a title and an image. day by day number of notice will be more and more in numbers. I want to load first 6 notice with respect to child "timestamp". and when some one press load more button next 5 item will load followed by first 6. I want this to save bandwidth of both user and firebase. Can you help me to solve this?
– smnadim21
Nov 14 '18 at 7:56
If you want at some point to try Cloud Firestore, this is a recommended way in which you can load more data on button click.
– Alex Mamo
Nov 14 '18 at 12:41
thank you @AlexMamo :)
– smnadim21
Nov 15 '18 at 14:24