Question: I have a RecyclerView and I need some `if statement` in my Adapter to make RecyclerView skip and do not create an item if one field in my ViewModel is empty. For example I have ViewModel with title and picture in it, so if the title is empty - do not create an item for it. So:

```
if (TextUtils.isEmpty(viewModel.getMessages().getTitle())) {
//do something?
}

```

This should be easy enough, but I just started practicing RecyclerView :)

Answer: 
There are several ways of approaching this:

1. First, you can just hide the ViewHolder instance that is passed in onBindViewHolder(). RecyclerView doesn't care how you bind your data with UI. Just do stuffs and update your UI here in onBindViewHolder().

```
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    if (TextUtils.isEmpty(viewModel.getTitle())) {
        holder.itemView.setVisibility(View.GONE);
    }
}

```
2. Filter your data beforehand before passing it to your RecyclerView.Adapter class. This is the recommended way as you don't want to mix your "data source" code with your "UI" code. Your RecyclerView.Adapter should only concern with populating UI. If you use RxJava, this can be achieved with just one line code.

```
getYourListObservable() 
    .filter(new Predicate<ViewModel>() {
            @Override
            public boolean test(@NonNull ViewModel viewModel) throws Exception {
                return !TextUtils.isEmpty(viewHolder);
            }
        })
    .subscribe(...) // this is where you pass data to your RecyclerView.Adapter object

```

I recommend the second approach cos it makes your code a lot cleaner.

PS: This is retro-lamdba code

```
getYourListObservable() 
    .filter(viewModel -> !TextUtils.isEmpty(viewModel.getTitle))
    .subscribe(...) // where you pass data to RecyclerView.Adapter object

```
check your list and if the current item is null or not. If it is, then remove the item from the list and call notifyDataSetChanged();

```
  if ((android.get(position).getname())==null) {
                         pos = android.get(position);
                         android.remove(pos);
                          notifyDataSetChanged();}

```