I have a recyclerview I want to display post in recycler view ..what my problem is I want to display only posts that as popularlist="true" in the database...there are photo that I don't want to display
please take a look at database structure ..over here popularlist="false" by default by all photo I want the recycler view to check if the popularlist="true" it needs to display in recycler view if its falseit should not display the photo ....can any one please tell me how can I do this ...
@Override
public int getItemViewType ( int position ) {
int viewType;
if (moviesList.get(position).getType_post().contains("Photo") ) {
viewType = IMAGE_TYPE;
} else if(moviesList.get(position).getType_post().contains("Video")){
viewType = VIDEO_TYPE;
}
return viewType;
}
I used this code for checking photo or video ...I don't know about filtering
what I have tried I created an interface as listviewmodel below
interface ListViewModel {
int VIEW_TYPE_PHOTO = 1;
int VIEW_TYPE_VIDEO = 2;
int getViewType();
}
and created 2 model class called photoviewmodel and videoviewmodel which extends listviewmodel
class PhotoViewModel implements ListViewModel{
String image_path;
public PhotoViewModel(String image_path) {
this.image_path = image_path;
}
@Override
public int getViewType() {
return VIEW_TYPE_VIDEO;
}
}
in fragment where I get photo I add this code where recycler view is in
List<ListViewModel> listViewModels = new ArrayList<>();
for (Photo photo : photos) {
if(photo.getPopularlist().contains("true")){
if(photo.getType_post().equals("Photo")){
List<PhotoViewModel> pho = new ArrayList<>();
PhotoViewModel p = new PhotoViewModel();
p.setImagePath(photo.getImage_path());
pho.add(p);
listViewModels.add(new PhotoViewModel(photo.getImage_path(),photo.getDescription(),photo.getDate_created()));
// Log.d(TAG, "onDataChange: alphs"+photoViewModel1.getImagePath());
}
if(photo.getType_post().equals("Video")){
listViewModels.add(new VideoViewModel(photo.getImage_path()));
}
}
}
it display the body but I am not getting image path and other thing which I have add in fragment over here