RxJava lets us use filter()
to keep certain values that we don't want out of the sequence we are observing. In the previous chapter, we used the installed apps list in a few examples, but what if we want to show only the installed app whose name starts with C
? In this new example, we will use the same list, but we will filter it, passing the proper predicate to the filter()
function to include the values we want.
The loadList()
function we had in the previous chapter changes like this:
private void loadList(List<AppInfo> apps) { mRecyclerView.setVisibility(View.VISIBLE); Observable.from(apps) .filter((appInfo) -> appInfo.getName().startsWith("C")) .subscribe(new Observer<AppInfo>() { @Override public void onCompleted() { mSwipeRefreshLayout.setRefreshing(false); } @Override public void onError(Throwable e) { ...