I’m trying to let my users know that no tweets were found in cases where the SearchTimeline search returns no results. I’ve currently set up a recycler view with a SearchTimeline attached to it. I’m also using an adapter data observer to observe when the data contents of the adapter changes, and display a toast when the item count is 0 like so:
recyclerView.setAdapter(timelineAdapter);
timelineAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
if (timelineAdapter.getItemCount() == 0) {
((HomepageActivity) getActivity()).showToast(getActivity(), "No tweets found.", Toast.LENGTH_SHORT);
}
}
However, this is not working as intended, as there are cases when tweets are found yet the toast still pops up. How would I fix this issue? Thanks.