• 12
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Visibility gone in recyclerview still occupies spaces?

Here is my current code. I want to hide a specific item on my recyclerview but when I use visibility.gone still occupies spaces on the recyclerview. I also tried all the possible solutions How to hide an item from Recycler View on a particular condition? Any help

  for(int j =0; j < minusList.size(); j++){
      int availableRooms =  minusList.get(j);

      if(norooms > availableRooms){ //norooms is the number of rooms wanted
      holder.itemView.setVisibility(View.GONE);
      mAdapter.notifyItemRemoved(position);
     }else{
      holder.rRoomsLeft.setText("Room available");
     }

}

Here is my XML

<android.support.v7.widget.RecyclerView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false" />

Please try this one

    for(int j =0; j < minusList.size(); j++){

      int availableRooms =  minusList.get(j);

      if(norooms > availableRooms){        //norooms is the number of rooms wanted
        holder.itemView.setVisibility(View.GONE);
        mAdapter.notifyItemRemoved(position); 
     }else{
         holder.itemView.setVisibility(View.VISIBLE);
         holder.rRoomsLeft.setText("Room available");
     }
}
  • 0
Reply Report

I guess you say "occupy space" because row is there but not displaying "Room Available".

Remove one row from RecyclerView is done by remove it from the underline list first and call either notifyItemRemoved or notifyDatasetChanged, not by hiding the rows's view.

In your case you need to remove items from minusList first and then call notifyItemRemoved, else if getItemCount() still returns minusList.size, RecyclerView still thinks row is there, even it is not visible.

  • 0
Reply Report