Stop Swiping after the end of the items in ViewFlipper - android

I am using Viewflipper in my application where I am getting some(x) number of items in the Viewflipper.
Now what is happening is that it showing the first item in the continuous scroll after the last item.
I need to stop it as the scrolling needs to get stopped in any particular direction after the last item is reached and vice a versa.
Thanks,
David

If you are using timed interval flipping, you can call stopFlipping() when you hit the last view.
If you are doing it manually via showNext() and showPrevious(), then you can simply set a flags in your code to check for the first and last views and handle the swipe actions. For example:
if(lastFlag==true)
{
}
else
{
vf.showNext();
}
Here's a good tutorial on using ViewFlipper:
http://www.techrepublic.com/blog/app-builder/a-dog-limps-into-a-saloon-a-tutorial-on-androids-viewflipper-widget/634

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 get whole scroll event when removing element from adapter of recyclerview?

I'm trying to create "sticky headers" on a RecyclerView (which uses a LinearLayoutManager) but now I'm facing a problem. When I click on one item of the list, a new item is automatically inserted just below it and the RecyclerView's default animation is shown (the one which smoothly adds and shows the new item). When I tap the initial item again, this new added item is removed, and the RecyclerView's default animation is shown again (the one to slowly hide the removed item).
I have completed all the sticky headers functionality but now my problem is that when I click the last list item and the hide default animation is shown (with a scroll up), my sticky headers don't work. I need to know (and here is were I'm stuck) how to get notified while this RecyclerView animation is being performed when adding/removing items. I need to get notified with all the animation steps, not only the start and end ones.
So far I've tried to use a RecyclerView onScrollListener and a ViewTreeObserver (attached to the added/removed view) but neither worked. If someone could give me some help, it would be really appreciated.
Thanks in advance to all the Stack Overflow community

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

Refreshing views in Android HorizontalListView

I am creating a HorizontalListView using the DevSmart library (GitHub link). When a user clicks on an element, I am catching the event and want to refresh all the views so I can show the user's selection. I've tried a bunch of different things and just can't get the HorizontalListView to refresh its views:
// does not work
mHorizontalListView.invalidate();
mHorizontalListView.requestLayout();
// does not work
mHorizontalListView.notify();
// does not work
mHorizontalListView.notifyAll();
// works, but scrolls to position 0 which isn't desirable
mHorizontalListView.setAdapter(mHorizontalListViewAdapter);
Is there any analog to invalidateViews on regular ListViews that I'm missing here. I know my selection update code is working because if I scroll the selected element on and off, when the element shows up again and has to be rebuilt, it shows up properly.
Maybe you need notifyDataSetChanged() method

Animating a listview item takes effect on multiple rows

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.

Categories

Resources