Skip to content Skip to sidebar Skip to footer

Load Image In Android Studio

I want to show image in ImageView from my database... but I was failed.. and no error showing... this is my MainFragment (By the way Detailtxt is working normally..) public class M

Solution 1:

You can use a third party library named Picasso to display image .

First add the gradle dependency in your build.gradle file

compile 'com.squareup.picasso:picasso:2.5.2'

After adding , your build.gradle file may look like this

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile'com.android.support:appcompat-v7:23.0.0'compile'com.squareup.picasso:picasso:2.5.2'
}

Then instead of this

getActivity().runOnUiThread(newRunnable() {
                        @Overridepublicvoidrun() {
                            //gambarImageLoaderimgLoader=newImageLoader(getActivity());
                            imgLoader.DisplayImage(egambar, img);

                            detailtxt.setText(edetail);
                        }
                    });

Use this

getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //gambar
       Picasso.with(getActivity()).load(egambar).into(img);
                        }
                    });

EDIT

If you do not want cache

getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                //gambar
                              Picasso.with(getActivity())
                                .load(egambar)
                                .memoryPolicy(MemoryPolicy.NO_CACHE)
                                .into(img);
                            }
                        });

Post a Comment for "Load Image In Android Studio"