문제

I'm trying to load an image in a dialog via "Lazy Image Loader" to an imageview. I've included two code snippets to show the way I'm calling it.


----EDIT-----

Now Using universal image loader 1.8.6

Log.i(Utils.TAG, "Show Photo");
ImageLoader imgLoader = new ImageLoader(a);
imgLoader.DisplayImage(strUrl, image);

this is how i'm calling it since @TalhaQ way didn't work. Said it did not accept those number of paramaters


---- ORIGINAL--- Log cat show a valid url and image when i go to that url. Any ideas?

Utils.java

public Dialog openFeed(final Activity a, final long id) {

    final Dialog dialog = new Dialog(a);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.getWindow().getAttributes().windowAnimations = R.style.dialog_animation;
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.feed_item);


    //Set the Title & Descr to the Item Selected
    TextView title = (TextView) dialog.findViewById(R.id.txtItemTitle);
    title.setText(strTitle);

    TextView descr = (TextView) dialog.findViewById(R.id.txtItemDescription);
    descr.setText(strDescr);

    ImageView image = (ImageView) dialog.findViewById(R.id.imgFeedImage);


    Log.i(TAG, "strUrl: " + a.getResources().getString(R.string.photoURL) + strUrl);

    ImageLoader imageLoader = new ImageLoader(a);
    imageLoader.DisplayImage(a.getResources().getString(R.string.photoURL) + strUrl, image);

    Button CommentButton = (Button) dialog.findViewById(R.id.dialogButtonComment);

    // if button is clicked, close the custom dialog
    CommentButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

            final AlertDialog addComment = Utils.openComments(a, id);
            addComment.show();
        }
    });

XML:

<ImageView
    android:id="@+id/imgFeedImage"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_alignLeft="@+id/txtItemDescription"
    android:layout_alignRight="@+id/txtItemDescription"
    android:layout_below="@+id/txtItemDescription"
    android:contentDescription="@string/itemicon"
    android:src="@drawable/gplus"
    android:scaleType="fitCenter"
    android:maxHeight="200dp"
    android:visibility="invisible" />
도움이 되었습니까?

해결책

I am also using the same Lazy Image Loader.I think you are not passing the context correctly.

   int loader = R.drawable.loader;//Old image in the imageview
   ImageLoader imgLoader = new ImageLoader(ctx); // ctx is the context
   imgLoader.DisplayImage(image_url, loader, image);//image is the imageview,image_url is the url to image

Check out my output.If you still needs any help i am attaching my sample.Download it.Check out the link

enter image description here

다른 팁

When you load image in dialog than the below scenario occurred in image downloaded therefore you should handle ClassCastException inside the image loader below code will help you . That exception not occurs if imageview is inside list which load in fragment or activity or imageview inside activity

Activity a= (Activity)(photoToLoad.imageView.getContext());

You can't assume a Context can be casted to an Activity. Hence the exception: You're attempting to cast a Context that is in fact a ContextThemeWrapper to an Activity.

You can replace

Activity a= (Activity)(photoToLoad.imageView.getContext());
a.runOnUiThread(bd);

with e.g.

photoToLoad.imageView.post(bd);

to post a Runnable to UI thread message queue, similar to Activity runOnUiThread()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top