ViewPager and longclick - android

I have a layout that is over top of a viewpager.
The viewpager is functioning as a dynamically changing background.
Upon a long click of the viewpager (long clicking the background), the foreground elements should disappear.
I put a long click listener on the viewpager, but it doesn't respond to this out of the box. This linked answer seems to touch on the subject, but I'm not sure how to implement it, help?
https://stackoverflow.com/a/11303508/727429
I'm also experimenting with other UX (clicks vs buttons vs motion gestures to do the same thing) but for now I want to solve this problem

The answer is to set a listener inside the viewpager's instantiateItem class.
Basically declare your View within that, and set an onClickListener on that

Related

Preventing the on-Click listener from calling itself on hidden views in Android app

I've design the user interface of my app as a collection of views, not activities or fragments. I manage the showing and hiding of views on this collection of views which are right on top of each other.
I believe I chose the wrong design principle to use for my app. The problem I am having is that when I hide a view in order to show another one; the button that resides on the hidden view fires its on-Click listener.
After reading some of the Android Reference documentation, I see that the view tree will navigate down the hierarchy of views in order to consume the touch event. It is then that the on-Click listener of this button is called.
What I need is something to prevent the button from the hidden view to stop calling itself when the user touches the shown view. I know that calling setVisibility(View.INVISIBLE) stops the on-Click listener from being called.
I was thinking of the ViewTreeObserver class that will allow me to create a listener of view hierarchy that somehow allows me to get a handle of all the hidden views in order to call setVisibility(View.INVISIBLE) on the hidden views.
Any ideas or advice
When you do setVisibility(View.INVISIBLE) for a view, it will still present in the layout. So instead of setVisibility(View.INVISIBLE), try setVisibility(View.GONE).
This will remove the view completely from the layout including the onClickListner attached to it.
When you want that view back, you can use setVisibility(View.VISIBLE) to get it back.

Remove Gesture Listener from a view in activity

I have a requirement to change the activity on swiping it either left or right.
For achieving this I use this link and complete my task. Now I have a problem whereas the activity also has a seek-bar that needs to swipe in either direction to change its position. Currently, whenever I move the thumb of the seek-bar the gesture listener of activity get activated and changes the Screen.
So How could I remove the listener from the seek-bar?
If you want to change between several views by swiping left and right, I suggest that each of the activity you currently have, you transform them into fragments, and then have a container activity which will host a viewpager. This way, all the swiping is handled for you, and your seekbar will still work.
I handled this scenario by adding a hack.
Actually I disabled the gesture listener whenever user start moving thumb and enable it again when user leave it. Hope it helps someone having the same problem.

Prevent onFocusChanged firing when ScrollView is scrolled

I have a problem where I have several TextView objects in my Activity. More than can fit on the screen view so I have placed them inside a ScrollView.
Now each TextView item is placed into a RelativeLayout before placing onto the ScrollView.
Each RelativeLayout object then has onClickListener and onFocusChangedListeners assigned.
Each Listener implements a method that pops up a dialog to enable the user to edit the value stored by the TextView.
The problem that is occuring is that when the screen is scrolled the onFocusChangedListener event is fired causing the dialog to appear for several items at a time.
Is it possible to detect if the Scrollview is scrolling and prevent the onFocusedChanged event firing?
I can post code if required but its quite large as the items added to the page are done so dynamically. This also means there is no xml for the layout.
I looked at using the ScrollView onTouchListener to add a flag ignoreFocusChange but it appears this would not work as the event was hit sveral times for one swipe/fling on the screen.
Please help
Regards,
Iain
After spending some time on this I found that the best solution for me was to remove the onFocusChangedListener and replace it with onTouchListener

Change ListViewItems Layout with a Right Swipe. Android

i've now got the listview and it's touch actions and swipe actions working. But now i'm not sure how i can implement a swipe effect, like it's in the twitter app.
I've found in the internet that it's possible to animate 2 views with a viewflipper, but is it possible to animate two layouts in the same way?
Anyone out there, who knows how i can implement such a function?
The only thing i want is to switch the ListViewsItem layout with a swipe.
Simple, set both the item views in 2 separate thread and then start both of them.

Android: Next/Previous fling that sticks to the finger similar to Home Screen

I want to give my app a nice touch by allowing users to slide the page left or right instead of just using next/previous buttons (similar to the home screen).
What is the best way to do that? I assume I would have to override one of the Activity.on... methods and that I would also have to put my page's main View in a ViewGroup that allows me to shift pages left and right.
ViewFlipper is your friend!
Here you can see a nice video of the ViewFlipper in action and also a very good tutorial:
http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html
The solution is even easier these days with the release of Compatibility Package r3. You can download here: http://developer.android.com/sdk/compatibility-library.html
It includes
ViewPager: A ViewGroup that manages the layout for the child views, which the user can swipe between.
PagerAdapter: An adapter that populates the ViewPager with the views that represent each page.
and Fragment versions of those, if you are that way inclined.
The pager code is compatible back to API version 4 (1.6), and I just implemented a dynamically generated viewPager coming off a dynamically generated ListView in about 2 hours. I'm a novice, so this is definitely the preferred path.
There is an example app here: http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html
If one wants to flip between two activities perhaps one can apply this animated transition:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
finish();
//transition using XML view animations
overridePendingTransition(R.anim.slideinfromright, R.anim.slideouttoleft);
Use GestureDetector to detect if the touch event is a scroll.
If the first event to the first call to onScroll is ACTION_DOWN then you should see if it was a dominantly horizontal scroll. If so then your scroll is started and you should shift the absolute position of the view that fills the page.
For non deprecated absolute positioning, see my answer here Android: Alternative to AbsoluteLayout (I really do need absolute positioning)
You will want to be cautions of whether you return true to consume the touch events or not.
GestureDetector does not have a callback for scrolling having stopped. You will have to check if there was an ACTION_UP before you call GestureDetector.onTouchEvent and if there was an action up and you did have an unfinished scroll then you should set the absolute position to the destination location and use a TranslateAnimation to make it look nice moving from current to destination.
Edit:
GestureDetector did not work well at all if the child views also wanted to respond to touch events. I ended up creating a subclass of FrameLayout (one of the most basic layouts and the closest thing to a non intrusive parent view) and overriding dispatchTouchEvent. I just took all the events and did the detection myself.
cant we use Gallery view here?? with the adapter the whole page can be inflated inside gallery view adapter getView() and it will manage the left right scrolling perfectly.

Categories

Resources