这是我当前的代码。我想在recyclerview
上隐藏特定项目,但是当我使用visibility.gone
时,仍然在recyclerview上占用空间。我也尝试了所有可能的解决方法How to hide an item from Recycler View on a particular condition?任何帮助
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");
}
}
这是我的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" />
最佳答案
请试试这个
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");
}
}