Recyclerview Item Position Does Not Get Update
In the following code, I could able to delete the image via clicking imgBtn, but my images does not scroll the deleted image position, it just stays its current position, it does n
Solution 1:
If you want to remove Item from the recylerview. dont do it like this.
Because you using ItemData[] array
List<ItemData> numlist = new ArrayList<ItemData>();
for(int i= 0;i<itemsData.length;i++)
{
if(i == position)
{
// No operation here
}
else
{
numlist.add(arr_fav[i]);
}
}
itemsData = numlist.toArray(new String[numlist .size()]);
notifyItemRemoved(position);
notifyItemRangeChanged(0, mDataset.size());
If you convert it to List<ItemData>
Go with asadmshas's Answer
Solution 2:
You should avoid manually modifying the views when using a RecyclerView. Use the adapters notify* methods to push any updates to the list view. In your specific case I'd suggest using a List<ItemData>
instead of an array and then in your onClickListener
code I'd do this:
@Override
public void onClick(View v) {
itemsData.remove(position);
notifyItemRemoved(position);
}
I can't exactly tell how the data is used to populate your RecyclerView, I'm assuming it is itemsData, but you'd remove the item in question from it and then issue a notifyItemRemoved(position)
call to that adapter.
Post a Comment for "Recyclerview Item Position Does Not Get Update"