Skip items in recycler view

2019-01-26 18:26发布

Hi I want to skip some items from recyclerview.

here is the screenshot

Here is the bit of code

item_Data.xml

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:id="@+id/mainlayout"
android:layout_height="wrap_content">
<ImageView
    android:visibility="gone"
    android:id="@id/image"
    android:layout_gravity="center"
    android:layout_width="100dp"
    android:layout_height="100dp" />
<TextView
    android:visibility="gone"
    android:textStyle="bold"
    android:id="@id/title"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:maxLength="15" />

And recycler view is

   @Override
public void onBindViewHolder(final MovieViewHolder holder, final int position) {
    String download= news.get((position)).getDownloadLinkForApkNew();
    String desc_new = news.get(position).getApkJData();
    if (download.isEmpty()==false && desc_new.isEmpty()==false) {
        holder.movieTitle.setVisibility(View.VISIBLE);
        holder.imageView.setVisibility(View.VISIBLE);
        Picasso.with(context).load(news.get((position)).getBetterFeaturedImage().getSourceUrl()).into(holder.imageView);
        holder.movieTitle.setText(news.get(position).getTitle().getRendered());
    }

I don't want the items that doesn't have download and desc_new. My logic works items are not visible but they leave there space. how can I remove the spaces between the items.

7条回答
劫难
2楼-- · 2019-01-26 19:23
if (download.isEmpty()==true && desc_new.isEmpty()==true) {

        //Hide the items
   holder.movieTitle.setVisibility(View.GONE);
   holder.imageView.setVisibility(View.GONE);

}else {
   holder.movieTitle.setVisibility(View.VISIBLE);
   holder.imageView.setVisibility(View.VISIBLE);
   Picasso.with(context).load(news.get((position)).getBetterFeaturedImage().getSourceUrl()).into(holder.imageView);
   holder.movieTitle.setText(news.get(position).getTitle().getRendered())           
}
查看更多
登录 后发表回答