question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get item position after updating items

See original GitHub issue

Hello and thank you for your cool library ❤️ i have an implement of ViewBinder and in this binder i set position into models like this : `public class PositionViewBinder<M extends PositionViewBinder.PositionViewModel> extends ViewBinder<M> {

public PositionViewBinder(final int layoutID,
                          @NonNull final Class<M> type,
                          @NonNull final Binder<M> binder) {
    super(layoutID, type, binder);
}

@Override
public void bindView(@NonNull final M model, @NonNull final ViewHolder viewHolder) {

    super.bindView(model, viewHolder);
    model.setPosition(viewHolder.getAdapterPosition());
}


public static class PositionViewModel implements ViewModel {
    private int position;

    public int getPosition() {
        return this.position;
    }

    void setPosition(int position) {
        this.position = position;
    }
}

}`

but i need to update this position after another item removed because the position field hold old position how could i achieve this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vivcharcommented, May 30, 2020

then you just should remove item from the list.

void onFirstButtonClicked(YourViewModel model) {
  items.findAndRemove(model);

  adapter.setItems(items);
  adapter.notify()
}
0reactions
vivcharcommented, May 30, 2020

add special flag to your model, and update when it needs

class YourViewModel implements ViewModel {
    bool isLoading;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update/refresh specific item in RecyclerView
You can use the notifyItemChanged(int position) method from the RecyclerView.Adapter class. From the documentation:.
Read more >
Updating All Items Based on ItemCount & Position
If you have updated(add, remove or update) the items in the DataSource(`List` or ObservableCollection ), After that, you can use mAdapter.
Read more >
Updating data in an Android RecyclerView - Suragch - Medium
Updating data in an Android RecyclerView · Overview · Insert single item · Insert multiple items · Remove single item · Remove multiple...
Read more >
Difference between position getAdapterPosition(), and ...
Imagine that we have a RecyclerView that will display 10 items so it will create 10 items and call onBindView for those 10...
Read more >
Recycleview scroll back to first item when calling recyclerView ...
My app needs to adjust an item's position right after the recycleview is made ... items view first, then it scrolls back to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found