logo
Tags down

shadow

ViewPager + Picasso + multiple images from URL String array


By : user2175031
Date : October 16 2020, 08:10 PM
will help you Please help me. I'm following the example ViewPagerActivity from sample PhotoView of Chris Banes (https://github.com/chrisbanes/PhotoView) and I want to change the drawable with Picasso URL images. So, I'm trying to put multiple images in HackyViewPager via Picasso String array of urls. , I see something wrong, that is
code :
for(int i= 0; i < numbers.length; i++){
                System.out.println(strAry[i]);
                System.out.println(strAry[position]);
                Picasso.get().load(strAry[position]).into(photoView);
            }
            System.out.println(strAry[position]);
            Picasso.get().load(strAry[position]).into(photoView);
class SamplePagerAdapter extends PagerAdapter {

    private String stringDefinitionGemstonesPhoto = ("https://geology.com/minerals/photos/calcite-marble-127.jpg, https://geology.com/minerals/photos/calcite-concrete.jpg");
    private String[] strAry = stringDefinitionGemstonesPhoto.split(",");


    @Override
    public int getCount() {
        return strAry.length;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        PhotoView photoView = new PhotoView(container.getContext());
        try {
            new DownloadImageTask(photoView)
                    .execute(strAry[position]);
        } catch (Exception ex) {
            Log.e("Error", ex.getMessage());
        }

        container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        return photoView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        private ImageView bmImage;

        DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urlDisplay = urls[0];
            Bitmap myImage = null;
            try {
                InputStream in = new java.net.URL(urlDisplay).openStream();
                myImage = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return myImage;
        }

        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }
}


Share : facebook icon twitter icon

ViewPager unable to load images lazily with Picasso


By : paper100
Date : March 29 2020, 07:55 AM
should help you out Your first approach should work fine... if you implement it correctly. I would expect your code to crash with a NullPointerException.
Replace:
code :
ImageView imageView = (ImageView)getView().findViewById(R.id.fragment_image);
ImageView imageView = (ImageView)myFragmentView.findViewById(R.id.fragment_image);

How to specify multiple fallback images with Picasso?


By : mndev
Date : March 29 2020, 07:55 AM
To fix the issue you can do Natively there's no API for such functionality. But with some clever coded Picasso.Target you can easily achieve such functionality.
I'll add here a quick hack-untested code that should give you a rought idea on what to look for. You'll have to test and maybe fine tune, but that should be pretty OK.
code :
private static final List<MultiFallBackTarget> TARGETS = new ArrayList<MultiFallBackTarget>();

public static class MultiFallBackTarget implements Picasso.Target {

   private WeakReference<ImageView> weakImage;
   private List<String> fallbacks;

   public MultiFallBackTarget(ImageView image){
      weakImage = new WeakReference<>(image);
      fallbacks = new ArrayList<String>();
      TARGETS.add(this);
   }

   public void addFallback(String fallbackUrl){
      fallbacks.add(fallbackUrl);
   }

   public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from){

      removeSelf();

      ImageView image = weakImage.get();
      if(image == null) return;

      image.setImageBitmap(bitmap);
   }
   public void onBitmapFailed(Drawable errorDrawable){
      ImageView image = weakImage.get();
      if(image == null) {
          removeSelf();
          return;
      }

      if(fallbacks.size() > 0){
         String nextUrl = fallbacks.remove(0);
         // here you call picasso again
         Picasso.with(image.getContext()).load(nextUrl).into(this);
      } else {
         removeSelf();
      }
   }
   public void onPrepareLoad(Drawable placeHolderDrawable){}

   private void removeSelf(){
       TARGETS.remove(this);
   }
}

Display Images From Array of String URL's in ListView in Android Studio using Picasso


By : Raja
Date : March 29 2020, 07:55 AM
like below fixes the issue I am attempting to load an a listview that contains text and an image using picasso. I'm attempting to load the images using from their respective URL's that are in a string array. The text portion is loading in the listView. However, the images are not loading so all i get is a listView with the texts in their respective rows but no images. How can I do this by using Picasso? in advance! , I've modified your Adapter.
code :
........
@Override
public View getView(int _position, View _convertView, ViewGroup _parent) {
View view = _convertView;
ViewHolder viewHolder;

if (view == null) {
    view= View.inflate(context, R.layout.content_orders, null);
    viewHolder = new ViewHolder(view);
    view.setTag(viewHolder);
} else {
    viewHolder = (ViewHolder) _convertView.getTag();
}
    viewHolder.description.setText(descriptionArray[position]);
    Picasso.with(OrdersActivity.this).load(url[position].replace(" ","%20")).into(viewHolder.myImage);  //here i'm editting your url, because if your url contains and blank space you can't download image from url
    //for that i'm encoding your URL by replacing blank space with "%20"
return view;
}
 .....
 .....
static class ViewHolder{
 ImageView myImage;
 TextView description;
 public ViewHolder(View v){
    myImage = (ImageView) v.findViewById(R.id.imageView2);
    description = (TextView) v.findViewById(R.id.textView2);
 }
}

How to load images in ViewPager in Android with Picasso


By : Joebro622
Date : March 29 2020, 07:55 AM
Hope this helps I was't sure what to name the title, anyway.. I'm currently inflating a ViewPager with a TabLayout into a a dialog like this: , Well, you're creating the layout here:
code :
ViewGroup layout = (ViewGroup) inflater.inflate(resId, collection, false);
collection.addView(layout);
return layout;
ViewGroup layout = (ViewGroup) inflater.inflate(resId, collection, false);

ImageView imageView = (ImageView) layout.findViewById(R.id.id_of_your_imageview);
Picasso.with(mContext).load(R.drawable.id_of_your_image_resource).into(imageView);

collection.addView(layout);
return layout;

Picasso Download Multiple Images From URL


By : Ci noreply
Date : March 29 2020, 07:55 AM
I hope this helps . I may be being dumb, but as I believe you are using Java, may I suggest you use this tutorial.
This is some code to take all images from the website:
Related Posts Related Posts :
  • How to remove Specific activity/activities from activity stack based on some action?
  • How to address "Remediation for JavaScript Interface Injection Vulnerability"?
  • Function returned undefined, expected Promise or value. although i am returning snapshot.val();
  • How to check if new added item exist in recyclerView?
  • How to reconstruct 33-byte compressed NIST P-256 public key from 33 bytes?
  • Error: could not find com.google.gms:google-services:4.2.0
  • if I update the database by DB Browser, it does not change in my app
  • I want to get two jsonArray from one url by using String Request
  • Receive_SMS Permission issue
  • How to unit test retrofit call?
  • Retrieving Uid's from Firebase Database
  • How to automatically close rewarded video ad in onRewarded method
  • Check if two Location Instances are the same value?
  • How to get the base alphabet of a foreign word and sort them accordingly like in device local contact?
  • http2 doesn't seem to be working with OkHttp3 and retrofit2
  • Failed to resolve: com.google.android:flexbox:1.1.0
  • How to fix Xiaomi specific RemoteServiceException with notification icon?
  • Placing text in the center of a CircularProgressIndicator
  • Calculator that accepts floating point values
  • Bitrise error Could not find com.google.gms:google-services:3.2.1
  • Check if Input is empty doesnt work Kotlin
  • Could not find method compile() for arguments [com.google.gms:google-services:4.0.0]
  • View AGPS setting in Android
  • Am I doing dependency injection in activity code correctly?
  • React Native Gradle ImagePicker wont build
  • React Native changes to code have no affect on emulator app?
  • Get the TextView value of the gridview while clicking on an element
  • How to launch an intent for a third party app?
  • Going crazy trying to change android theme on Xamarin.Forms
  • Could not find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are
  • How can I capture variables inside of Context
  • React Native : Could not find com.android.tools.build:gradle:2.2.3
  • Google Login/Signin on Yandex Android extension
  • Retrofit generates wrong GET request parameters from Map<String : Any>
  • Flutter app crashing when opening first time with ClassNotFoundException on Android
  • Android LinearLayout programmatically one column left, one column float right
  • Kotlin - convert UTC to local time
  • Android'd ForegroundDispatch for NFC
  • How to use Shared Preferences in class to set all activities?
  • Synchronous Volley request locks up
  • How do I inherit a function from another class into an activity in kotlin?
  • BottomAppBar Navigation Icon with Badge
  • Change content_main XML in Basic Navigation Drawer Template
  • HERE SDK Android: PositioningManager not working with NETWORK_PROVIDER in 3.8 or 3.9
  • No response after putting in Header in request
  • Where are default shared preferences written to?
  • how to show a part of next image in daimajia slider?
  • AlertDialog Builder inside holder.itemView.setOnClickListener onBindViewHolder
  • Flutter Grid view is not scrolling
  • How to access view in addTextChangedListener?
  • How do I link multiple activities in android navigation editor?
  • Failed to resolve: com.google.android.exoplayer:extension-mediasession:2.8.4
  • how do I open another fragment after selecting the image in recycler view?
  • Send data from fragment to another fragment
  • Custom TitleView with Description and Preview Image Android TV (FireTV)
  • Gradle project sync failed. basic functionality (e.g. editing debugging) will not work properly
  • how to retrieve firebase storage images in release mode?
  • Android Studio: Could not find matches as no versions of com.android.tools.build:gradle are available
  • Getting a JSON Left side Value
  • Is it possible to use of Mobile data while transferring file via Wi-Fi Direct?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org