ListView, Gallery or HorizontalScrollView? - android

Alright, I want to do something like a Gallery of images, scrolling from left to right. The user is going to register barrages, and he needs to take many picture of this barrage. I already know how to save the data, and how to show using listview with adapter, I did with listview thinking that I could change to horizontal somehow, but I searched and I can't. What should I use to do that? What I want is a gallery with the first photo being a plus to when you click it opens a new intent that take a picture and a description of the pic and save it, I know how to do that with listview, but it's not what I want. I saw that gallery view is deprecated, so I should use HorizontalListView?

Gallery is deprecated, yes. So maybe HorizontalListView.
But i think, that you can use fragments with animation

Use linearLayout that is placed in horizontalScrollView and on runtime Add pictures to that LinearLayout that has orientation set to horizontal. Best practise will be create your own class where you will have specified LayoutParams that you will apply to each ImageView generated on runtime , then you just need to add it to layout.
You can define method like addPictures(LinerLayout yourLayout,int amountOfPictures,Array pituresPaths) that will be loop which will create ImageViews for specified amount of Pictures and paths you can take from ArrayEditLike xoxol_89 mentioned you can use Fragments , advantege will be that FragmentAdapter dynamically recreates and destroys fragment objects so that solution with many pictures will be more memory resource efficient

Related

Android ListView that contains images instead of text

I want to make an app for Android in Eclipse, when the user clicks a button, a camera component is opened and the user takes a picture and clicks save, after that I want that picture that he just took to show in a list. Then if he takes another picture, the picture shows below the first picture and just like that.
I know how to write the code for the camera element, but how can I do that when the user saves the picture that he just took, it would appear in the listview?
Something just like a listview with text and a TextEdit, but instead of text it would be an image and instead of TextEdit it would be the camera component.
Can you help me guys? Thanks!
This is pretty simple. Just create a custom adapter which inflates a row.xml (containing an imageview) in it's getView() method and set the image in there.
There are many many examples of how to do this, and lots on stackoverflow itself. This is a nice example of creating a custom adapter with an imageview and listview.

custom gallery with swipe

What is the best way to present a full screen picture gallery read from a directory.
I was thinking of using an ImageView for full screen bitmap display and then using viewPager for swipeing to the next image.
Which would mean that I would need to have at least PICTURE,PICTURE+1 and PICTURE-1 always in memory.
is this proper way or is there a better one?
Allows you to do what you want and recycles the fragments for reuse after swiping through
http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
-- Update --
As pointed out in the comment, the gallery is deprecated.
The gallery doc says to use a ViewPager or a horizontal scroll list : http://developer.android.com/reference/android/support/v4/view/ViewPager.html
http://developer.android.com/reference/android/widget/HorizontalScrollView.html
-- Old answer --
Is there a reason you wouldn't want to use the built-in gallery ?
http://developer.android.com/reference/android/widget/Gallery.html
As for managing memories and bitmap, the android put up a post on this :
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

Change ImageView content within a GridView in Android

I am new to Android and Java. I am building an app that allows users to push a button which launches an image chooser where they can select from images on the sd card. The app loads with a grid view with 2 cells. One cell has an image view that has a default image. The other is the button. Once, the image is chosen, the image view needs to be displayed in the Image View of the Grid View.
I am using a string path that is being decoded from the images uri to create a bitmap. I then am calling imageView.setImageBitmap(bitmap). This is doing nothing. I have tried updating the image resource with a different image in the drawable folders and still nothing. I added a seperate image view just under the grid in my activity, and that image is updating fine which leads me to believe that this has to do with the grid view (this is my first grid view).
Any help is very much appreciated.
Thank you.
GridView is maybe not the right choice if you've only got two cells. You will probably have an easier time with a simple LinearLayout that has the two items you're dealing with.
But, here's how you do it with a GridView:
Create your adapter by extending BaseAdapter. The most important method is getView(), but it's where you should be doing the least amount of work.
When the GridView goes to redraw itself, it'll go through for each visible position and call getView() for each one. You'll be supplied a View. If the view is null, inflate a new one from your XML resources, populate it, and return it. If the view is NOT null, populate the existing one with the appropriate data. The widget is being efficient by recycling views.
The trick you need is that when you want the image to change, you need to call notifyDataSetChanged() on your adapter in order to trigger the redraw (which is when you'll populate the new image in the view for the appropriate cell).
That's the two-minute version. At Google I/O a year or two back, they did a talk on The World of ListView and posted it on YouTube. It was a good talk and pretty much everything there applies to GridView as well.

Actions on gallery view android

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);

Custom Adapter for Gallery View in Android

hi i want to split my gallery with 5 images in 2 rows.
Please let me know how to do this in android using Gallery View & custom adapter for Gallery view.
Is there any sample code available please share it, i have already checked the previous posts in this site.
Thanks
If you still need this and Pagination instead of scroll will work for you, you might look at: https://github.com/sfarooq/PaginatedGallery
I designed it using ViewPager so you can manipulate the adapter to send any kind of views you want including two row views.
If you must use scrolling galleries you could implement two separate gallery in a vertical orientation and send touch events from each to the other.

Categories

Resources