how to put array of download URLs of images to viewpager - android

I made a view pager with an image view inside it, and I want to make something like an image slider using the view pager. I have an array of download URLs. how can i put those URLs to open the image to the image view. I tried searching for other tutorials but they all use bitmaps.

Use Global Array to store URLs and than display using GLide Like>>>
#Override
public Object instantiateItem(ViewGroup container, final int position) {
layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.image_fullscreen_preview, container, false);
ImageView imageViewPreview = (ImageView) view.findViewById(R.id.image_preview);
final ProgressBar pbLoad = view.findViewById(R.id.pbLoad);
String image = images.get(position);
imageViewPreview.setTag(image);
Glide.with(getActivity()).load(image).thumbnail(0.5f).crossFade().diskCacheStrategy(DiskCacheStrategy.ALL).into(imageViewPreview);
container.addView(view);
return view;
}

Related

ImageView won't initialized in view pager

I'm trying to create Intro Slider for users so they can better understand the concept of application, but i have problems in initializing image view inside view pager.
Here i'm setting layouts to view pager and setting parameters to it's layout:
#Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(layouts[position], container, false);
ImageView imageView = (ImageView) view.findViewById(R.id.image);
Picasso.with(WelcomeActivity.this)
.load(imageResources[position])
.into(imageView);
container.addView(view);
return view;
}
I have three layouts and three image views, but ImageView won't initialized and i can't set image resources to it. Images are not showing in image views and i'm getting no errors. What i'm doing wrong here?

Add Zoom in/out to ListView of Images?

I have a fragment which contains a ListView and multiple images (7-10) are displaced each time fragment is launched.
I tried using different libraries for the zooming purpose but the ListView won't show up as then I will have to replace ImageView with library's defined ImageView
How can I add zoom in/out for those images?
EDIT: I want to add zoom in/out to the ListView that contain different number of images on each load, as my question states.
EDIT 2: This is getview method of my Custom Adapter. How do I attach PhotoViewAttacher in it?
public View getView(int position, View convertView, ViewGroup parent) {
View iv = convertView;
ViewHolder holder = null;
if (iv == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
iv = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.image = (ImageView) iv.findViewById(R.id.imagview);
iv.setTag(holder);
} else {
holder = (ViewHolder) iv.getTag();
}
Picasso.with(context)
.load((Integer) data.get(position))
.resize(999, 720)
.onlyScaleDown()
.centerInside()
.into(holder.image);
return iv;
}
static class ViewHolder {
ImageView image;
PhotoViewAttacher mAttacher;
}
}
This is how I made it work
After importing PhotoView
In layout file (if you use layout):
<uk.co.senab.photoview.PhotoView
android:id="#+id/your_photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
... />
And in adapter
PhotoView photoView = (PhotoView) findViewById(R.id.your_photo_view);
Picasso.with(context)
.load(file)
...
.into(photoView);
Thanks everyone for your time.
Instead of taking simple ImageView in BaseAdapter's getView list item add
TouchImageView

How do I add a ProgressBar and then display a remote ImageView in a ListView?

I have a ListView of receipt data, which includes a vendor, value of the receipt, and the date on the receipt.
I'd like to add an lazy-loaded image of the receipt to my ListView. I have thumbnail images of the receipt stored in an AWS location, but the receipt images could be 'processing' and not immediately available. Unfortunately, the URL for the remote image is not available in my current ListView dataset, which means I have to call an async task to retrieve the receipt image data for each displayed row in my adapter.
To get the receipt image data, I have created a service call (I'm using Retrofit) to hit my API to pull down the JsonObject that contains the receipt image thumbnail location OR an indication that the image is still processing/not available. The receipt image data is requested via a receipt id.
Here's what I currently have:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ReceiptHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ReceiptHolder();
holder.txtVendor = (TextView)row.findViewById(R.id.vendor_field);
holder.txtAmount = (TextView)row.findViewById(R.id.amount_field);
holder.txtDate = (TextView)row.findViewById(R.id.date_field);
row.setTag(holder);
} else {
holder = (ReceiptHolder)row.getTag();
}
Receipts r = data[position];
String fullValue = r.amount_symbol + r.amount;
holder.txtVendor.setText(r.vendor);
holder.txtAmount.setText(fullValue);
holder.txtDate.setText(r.date);
return row;
}
public class ReceiptHolder {
public TextView txtVendor;
public TextView txtAmount;
public TextView txtDate;
public ProgressBar receiptFetch;
public ImageView receiptThumb;
}
So, when my custom adapter is performing the getView, I'd like the following to happen:
The ProgressBar receiptFetch to be set as visible on initial draw to indicate that the image is still being retrieved/processed. I'd like the receipt data to be visible and a ProgressBar indicating that the image is still being retrieved or processed.
Some kind of non-blocking mechanism to go back and set ProgressBar's visibility to GONE and simultaneously setting ImageView receiptThumb with the asynchronously retrieved URL for each row item as the task completes for that particular row.
Now, here's my question:
How do I get the View holder pattern to play nice without hanging up the UX? Ideally when the adapter is doing its thing, I could kick off an async task to retrieve the receipt image data for each receipt while populating the other fields inherent to receipt data... but I'm not sure how to capture the response to turn off the ProgressBar and go back to populate the ImageView.
I've been unsuccessfully dabbling at this for a bit, and I'm stumped. Does my question make sense? Any ideas?
You can use UniversalImageLoader library to load your remote image.
Refer this: https://github.com/nostra13/Android-Universal-Image-Loader
final View imageLayout = inflater.inflate(R.layout.list_item, null);
final ImageView imageView = ...
imageLoader.displayImage(images[position], imageView, options, new SimpleImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
spinner.setVisibility(View.GONE);
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
Picasso. Picasso is the answer.
Universal Image Loader would also work, but was simply overkill for the problem I was trying to solve. Picasso does inline lazy loading, and has options to allow for a temporary #Drawable to be shown while the thumbnail is retrieved.
I ended up doing the following - didn't need the ProgresBar anymore since Picasso took care of it. Note that Picasso can be used in a static way - but I had to create a custom OkHttpClient for our networking configuration :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ReceiptHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context)
.getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ReceiptHolder();
holder.txtVendor = (TextView) row
.findViewById(R.id.vendor_field);
holder.txtAmount = (TextView) row
.findViewById(R.id.amount_field);
holder.txtDate = (TextView) row.findViewById(R.id.date_field);
holder.receiptThumb = (ImageView) row
.findViewById(R.id.receipt_image);
row.setTag(holder);
} else {
holder = (ReceiptHolder) row.getTag();
}
Receipts r = data[position];
String fullValue = r.amount_symbol + r.amount;
holder.txtVendor.setText(r.vendor);
holder.txtAmount.setText(fullValue);
holder.txtDate.setText(r.date);
picasso.with(getActivity())
.load(r.medium_jpg_url)
.placeholder(R.drawable.ic_empty)
.error(R.drawable.ic_error)
.resize(100, 100)
.centerCrop()
.into(holder.receiptThumb);
return row;
}

Can't load image with Picasso into fragment view

I have a fragment that is suppose to populate a background with an Imageview that is created with Picasso.
public class Fragment1 extends SherlockFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Context c = getActivity().getApplicationContext();
View myFragmentView = inflater.inflate(R.layout.home, container, false);
TextView text = (TextView) myFragmentView.findViewById(R.id.text);
ImageView imageView = (ImageView) myFragmentView.findViewById(R.id.image);
String url = ModalScreens.byId(1).getBackgroundImagePath();
Picasso.with(c).load(url).fit().into(imageView);
return myFragmentView;
}
}
I can't figure out what I am doing wrong but the image wont load.
From your code it seems possible that you're loading a local resource and not from the web. If the former is the case, then you could just load it like
StackOverflow showing image View from local disk
If not and you're loading a web image, then this could be a variety of problems, here's some hopefully helpful troubleshooting
Have you added?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Is the link a valid (as adavis as suggested)? Free of spaces from the beginning and end what not. I would do a
Log.wtf("Testing valid URL", "|"+url+"|")
Is the image too large? In that case it might return a null
Image too large Stackoverflow answer
Is the Imageview properly set to display? I would confirm by initially setting it to some image like this
android:src="#mipmap/large in your layout xml for your ImageView

ImageView of ListView loading incorrect few second when scrolling ListView

I'm using ListView with ImageView is a element of List. I have got problem when fast scrolling my List : The system seems to be recycling views until it loads the correct position's view in my ListView, resulting in duplicated images and text for a few seconds. After that, ImageView display images correctly. I'm using Universal Image Loader library to load images.
#Override
public View getView(int position, View v, ViewGroup parent) {
final PhotoViewHolder holder;
if(v == null){
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.photo_item_horizonal_layout, parent, false);
holder = new PhotoViewHolder();
holder.imgPhoto = (ImageView)v.findViewById(R.id.imgPhotoIcon);
v.setTag(holder);
}else{
holder = (PhotoViewHolder)v.getTag();
}
//item variable is a element at position of ArrayList
ImageLoader.getInstance().displayImage(item.getImageUrl(), holder.imgPhoto);
...
}
Can anyone help me?
Thanks in advanced
Do one thing Download Aquery from This link put that .jar File in your Lib folder and change your code to this:
#Override
public View getView(int position, View v, ViewGroup parent) {
final PhotoViewHolder holder;
if(v == null){
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.photo_item_horizonal_layout, parent, false);
holder = new PhotoViewHolder();
holder.imgPhoto = (ImageView)v.findViewById(R.id.imgPhotoIcon);
v.setTag(holder);
}else{
holder = (PhotoViewHolder)v.getTag();
}
//item variable is a element at position of ArrayList
AQuery aQuery=new AQuery(v)
aQuery.id(holder.imgPhoto).image(item.getImageUrl().toString());
}
Use a placeholder image while image is loading . You can do that by UIL option:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.placeholder)
......
.build();
This should solve your problem.
Are you changing the image of the ImageView by yourself in a later part of the code?
if you do, you should call
ImageLoader.getInstance().cancelDisplayTask(holder.imgPhoto);
so that the library knows that the link between the image and the imageview is broken

Categories

Resources