Recyclerview : how to mix some post with image and no image?

En Baha :

I want to display in same recycle-view which is some post have image and some post does not have images.

I can retrieve all the post with image and non-image, but i want to change the size of the post when the user only post text(no image).

I expect the output like twitter feed..some post with image and without image have their own size.

Usama Nasir :

Simple way to achieve this scenario is, All you have to do is create a view with both image and text, in recycler adapter check if image data is available make visibility of image visible else Image visibility gone.

Second Approach for this to make multiple view for RecyclerView.

 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {

        Log.d(TAG, "onBindViewHolder called");        
        ContentItem item = mContentItems.get(position);

        if(item.getName()!=null){
             holder.textName.setVisibility(View.Visible);
             holder.textName.setText(item.getName());        
        }else{
             holder.textName.setVisibility(View.GONE);
        }

       if(item.getPreviewImageDefault()!=null){
             holder.imageIcon.setVisibility(View.Visible)        
             Picasso.with(mContext).load("file://" + item.getPreviewImageDefault()).into(holder.imageIcon);  
       }else{
             holder.imageIcon.setVisibility(View.GONE)
       }
 }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77434&siteId=1