Animating a listview item takes effect on multiple rows - android

I'm having a strange issue. I need to implement swipe to delete in my listview. When user swipes left/right, I need to animate a delete button into/out of the screen and then on delete button click I need to delete that item from listview.
I am using Commonswares [TouchList] (https://github.com/commonsguy/cwac-touchlist/tree/master/src/com/commonsware/cwac/tlv) library to achieve that. In onFling method it gets the position of the swiped row and send it to onRemove method in my activity. I can delete the item accurately. But if i animate the row at swiped position, multiple rows get effected. I am not able to fix this issue nor am I able to find any help.
Any help will be appreciated.

I had a similar issue to this which was down to Android's view recycling.
(A good explanation of it is available here)
To resolve I simply reset the animation in the item's OnResume method as I didn't need to retain the animation for the item which has scrolled out of view.

Related

RecyclerView Reorder Items with ItemTouchHelper.SimpleCallback and call notifyDataSetChanged() on Gesture start

I Have a RecyclerView that lets the user reorder its items when long taping using ItemTouchHelper.SimpleCallback, the problem is that UX wants to hide a handle on all item views BUT the dragged one, to provide some kind of feedback when the long tap is detected and the card can be dragged.
The issue is that as soon as I try to call notifyDataSetChanged() to make the items update acordingly and hide the handle icon, the Drag functionality stops working.
I tried calling this logic inside the onMove first, and then, inside a ItemTouchListener:onLongClick to try to run this logic and update the recycler before the item gets moved but the same result, as soon as I add a call to notifyDataSetChanged() the drag functionality stops working, any workarrounds to acomplish this functionlity?
To resolve the issue: replace the notifyDataSetChanged call with 2 calls to notifyItemRangeChanged(start, end) to update all views before and after the one being dragged, leaving the dragged one untouched, then the views are updated properlly and the drag gesture is not affected.
This could probably be solved using a DiffCallback too.

How to identify if a row is visible in a listview

I have a situation involving animation of listview's item appearances.
I have a few views in a ScollView , the last of which is the listview. I have attached an appearence animation of the row (a fade in animation).
The problem I have is that when the screen is loaded , the getView() of listview already executes for the initial items , even though the listview is not currently in view.
Hence when a user scroll downs , he sees the list plainly.
I am unsure how to go about this situation . Is there any callback that can be invoked when a row from a listview becomes visible on screen ? .
Yes there is a callback (OnScrollChangeListener), first visible index and last visible index etc. You can achieve what you are trying to using combination of these.
But you need to try that yourself first. No one can simply write a code for you.
You can learn about listview here

How to implement expandablelistview with Drag and Drop List Items in android

I wan for the ExpandableListView with Drag and Drop of ListItems in Android,i google it but i haven't found any good tutorial or any good link for ExpanadableListView with drag and drop list item. Please suggest me where can i learn to implement drag and drop for ExpanadableListView. Any tutorial,sample code would be appreciated greatly .Help me. Thank you.
The basic idea behind drag and drop can be divided into two sections, like updating the UI and updating the data. Updating UI starts with hiding the selected item and show a detached row with the same value as the hidden item, this will show that the selected item is ready to drag, now move the detached row over the list view based on the touchmove event, when the user takes the hand ie the touchup event or any other event that happens while dragging, get the current row at which user touched last , remove the detached row and do the data updation and invalidate the expandable listview, this will redraw the list based on the new set of data and the user will get a feeling that the item is dragged and dropped in the list.
I have done something similar, see this

ListView updating Items without being recreated

I want my ListView to work something like the following:
When I press a button (probably from context-menu), I want the user to be able to select more then one item from ListView (probably using check-boxes), but those check-boxes should not be visible before that.
So, the point is, after the user presses a button (let's say "Delete more items"), the listview, should update itself, and appear on every row of the list, a checkbox should appear (allowing me to select the items ID to pass those to server).
How can I achieve that, without having to recreate the list from zero? (how to setVisibility ON, keeping the other content of the ListView as it is, and not doing another request to server).
PS. If you guys, have another better idea, on achieving the Delete More Items, would be much appreciated!
This is just an idea, haven't tried it myself: you build in a checkbox in your listitem layout. Normally, in the getView of your adapter, you set it invisible with
checkBox.setVisibility(8);
When you want to show them, you set some boolean
showBoxes
of your adapter to true, then in the getView oyu don't hide the checkboxes.
Then
notifyDataSetChanged
on the adapter.
Hope it's clear what I mean.

List view refresh in android

I have a list view. When user scrolled till end, the i load more data. But its focus move to the first row of the listview. I want that the focused row should not be changed when list is updated. For example if i am in 10th position on the list. When list refreshed , i should remain on 10th. How to achieve it?
Does the programatically scrolling the listview by using setSelection() method work for you? Or are you looking to do something else?

Categories

Resources