• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

View Pager Code Not Working

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there


Here is I am using ViewPager in android.I want when a User clicke on A picture then a Intent will open.But Know when i Scroll from one activity to another The Intent is calling This is my code




What Else i Need to change in My Code that When a user Clicks on A Particulr Image then Only the Intent Will open Not in Scrolling?


Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you overriding onPageScrolled if what you really want is to detect clicks?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want that If Someone Clicks on a particular Image then Information about that Image will display...
So I want to start a New InfoActivity There


Any More Clarfication?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood. To phrase it differently: Does "onPageScolled" sound to you like a callback to detect a click? Or might there be some other callback better suited for that purpose?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to detect some click when a User clicks on a Particular Image Not in all Images?


So what should I do?


 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a callback that triggers only if that image is clicked. That probably means attaching the listener to the View that holds the image, not to the ViewPager.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get full Point How to use callback?


Can you clear it some more or can you give a link or Source of Callbacks in Other Views in Android?


 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The callbacks here are the methods defined by the OnPageChangeListener: Callback_(computer_programming). They're "called back" from code other than where they are defined. You may not have heard the term, but anyone using event-driven APIs (like GUIs, whether Android or AWT/Swing) will be familiar with the concept.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok
I Tried to use all 3 Methods in Callback

Originally I posted code using these method
But None of them working like what I want



Any Other Suggestion?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, I think you missed pretty much all the points I've been trying to make in all my replies. More directly: Why are you listening for events in the ViewPager if you're actually interested in events concerning the images (or whatever View they are part of, which you haven't said so far)? If you are interested in "click" or "touch" events, why are you listening for "page scroll" or "page select" events?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok


So what to do know?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attach appropriate listeners to whatever View holds the images (you haven't said what kind of View that is, so we can't help with that).
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok

here is my complete code of PagerAdapter Code





Can you know figure out?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure you can figure it out on your own; that'll be much more useful as a learning experience for you. Look up the javadocs of the View holding the images to learn what listeners you can attach to it. Don't forget to check the superclass(es) of it as well. Which listeners are those? Which of those suggest themselves if you want to handle clicking on it?

A hint: listeners are generally attached via methods called "setOn..."
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok

So I am using LinearLayout to handle all my Views in it.
So How can I use refence of that layout in MainActivity.


I have posted all my code.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The kind of layout is irrelevant. As I said (3 times by now), the View that holds the images is important.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is few Changes that I made in My Code and At least it let me Understand How these method Interact with Each Otehr





By This I have seen that Each time when we switch to a New Screen Old View is Removed than Instatite Item is Called again and again.
My Question is How can I get currently focused View and Its id?
 
Ulf Dittmer
Rancher
Posts: 42969
73
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ulf again as usual
I solved my problem by your direction

I have fetched view position in instatitem() method.
And it works


Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic