I have an 2 adapters extending BaseAdapater. The first Adapter (let's call it imageAdapter) loads an image base on an ID, the second adapter (pageAdapter) builds grids of images from the first adapter. I set the second adapter to a gallery. The idea is that I can sort have pages in an album where there are multiple pictures on each album.
Now I want to the imageViews to fire off clicks, so I set an onClickListener for each of the imageViews from the imageAdapter. The problem is that after I set the onClickListener, I cannot scroll the gallery by touch/fling/scrolling on the images anymore. I think it's an issue of parent/children event pass through thing.. but I am not sure how to fix it exactly. Please help.
This is a wild guess based on an experience with ListView (where one clickListener worked but the parent onClickListener did not), but setting the onClickListener on the imageViews might have made it so they have taken away the focus, and now your other touch events are not registering.
try setting myImageView.setFocusable(false)
I am assuming that everything worked as expected before you added the onClickListener to the ImageViews.
I solved this problem by subclassing Gallery and overriding onDown() and onSingleTapUp(). I have to also implement a pointToChildId() method to translate motion events to item ids. =) it was a lot more work than I initially planned for, but it works now and I am quite happy with the solution.
Related
I am developing an activity with a ListView in which I need to change the current row by another layout by clicking on the row, and I'm not finding any way to do as much as I look (I take hours searching for possible solutions and I have not seen any reference to this problem). I do not know if this can be done in Android, but if anyone has an idea of how to do this would be appreciated.
Thanks in advance.
PS: The ListView control is normal and just want to replace a layout with a different layout. I'm using the API 15.
Use a ViewSwitcher
http://developer.android.com/reference/android/widget/ViewSwitcher.html
A ViewSwitcher is -
ViewAnimator that switches between two views, and has a factory from
which these views are created. You can either use the factory to
create the views, or add them yourself. A ViewSwitcher can only have
two child views, of which only one is shown at a time.
I suggest merging the two layouts in a single one and hide the second one. In your adapter data you should have a flag or something to indicate which layout to display. When you click a row, toggle that flag for the selected item and notifyDataSetChanged() on the adapter. This will make sure the changed layout remains even if you scroll up and down and the row goes off screen.
A more optimized solution is to have different item types in the adapter.
I want to create a horizontal listview which contain many item, one item will contain a image. When user slide listview => the count of item will be fix when it display, example display only 3 or 4 image. How can I do that? Many thanks.
Edit:
I use this
to create a HorizontalList view, everything is ok but I don;t know how to make the Next and Previous button work! Any idea?
Instead of a horizontal ListView (which, as far as I know, isn't offered by the Android SDK) you can use a HorizontalScrollView. You can add the items like to any other kind of layout class.
It looks like what you are looking for is a Paginated Gallery. I have written one here.
Its still only a couple of days old but hopefully the included Activity code will get you off the ground.
I am trying to get a button to show up on my list item (declared as android:visibility:"gone" in the XML) to show as visible when I perform some gestures on it. However, how can I actually notify the getView method correctly to display the button only on the listview item?
I tried using getChildAt(position) which ended up displaying several buttons at once.
I tried passing in the position for example I detected that the gesture was performed on from pointToPosition and passed it into the adapter for the getView method to display, but it had the same problem of displaying several at once.
do anyone know how can I solve this?
I think you may have a misunderstanding of how Adapter.getView() works its meant to create or reuse layouts when rendering the ListView it also needs to be fast so conditional manipulation in this method is discouraged. Although ListView.getChildAt() may work it does not effectively use the API. Your adapter will have a setViewBinder() unless you're using an ArrayAdapter (if so I suggest using SimpleAdapter because of the additional features). Use your ViewBinder implementation to switch the visibility of the button.
If you'd prefer to continue to use ArrayAdapter use ListView.getChildAt(int) to findViewById(R.id.your_button).setVisibility(). If this is what you already tried and its setting all the buttons visible then please post the related code.
i have two gallery views in my single UI screen or you may say activity, i want to have listener in such a way that on scroll of one gallery view the other should also scroll , i tried giving listener to one gallery and calling the other one gallery view into that ., but its working for me , pls can any one help me..
thanks in advance
Datta
You could try to find the position of one of the galleries with Gallery.setOnItemSelectedListener() and then update the other gallery with Gallery.setSelection().
I believe the Gallery view is missing a lot of functionality (or is broken) as compared to ListView or GridView. In this particular instance, you need a "setOnCenteredItemChangedListener" or something like that. However, the documentation does not show anything close to this.
One option would be to implement your own Gallery class using HorizontalScrollView.
Another (hacky) option would be to rely on your Gallery adapter to push the current position being fetched (which may NOT be the one displayed in the middle) and use that to guess the currently selected position.
You have to override the scroll event of your first gallery and inside this method you should call the onScroll event of your second gallery like this,
gallery_two.onScroll(MotionEvent e1,MotionEvent e2,x,y);
I have a gallery and when a image is selected, I want to start new thread (for loading other images). But I don't want to do it while the gallery is scrolling. How can I know the state of the gallery and if it is still scrolling?
I can't use "setCallbackDuringFling(false)" because I have a textview under the image that has to be updated during the scrolling...
Thanks!
Marc
I think you could have a go with setCallbackDuringFling method. From what I understand, if you set it to false, it shouldnt be possible to select an item while fling is being computed.
Use a Handler that is called from the onItemSelectedListener that updates the last time that an item was selected (every time the foremost item changes this listener is fired) and use a timeout value to determine when scrolling ended to determine if scrolling is still occurring.
However, I have the exact same thing in andAMP... I have a FrameLayout with a Gallery and 2 textviews to show the foremost selected Artist and Album... I use onItemSelectedListener to update those TextViews and it works fine. If you have the TextViews in a FrameLayout like me you have to use bringChildToFront to get them to show over the Gallery (add the Gallery last).
As far as Lazy Loading (which I am assuming that is what you are doing). There are a couple of great tutorials about how to do this.
http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html