1

please construct my code, i want a loading image while the result is not ready..

i use glide for this code..

imageView = (ImageView) rootView.findViewById(R.id.imageView);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView);

imageView3 = (ImageView) rootView.findViewById(R.id.imageView3);
Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView3);

as you can see in my code, i use placeholder indexloading.

but gif loading image is not working in placeholder.

please give me a sample code that solb my problem..

also code that work in a fragment..

here is the complete code..

HomeFragment.java

package com.example.administrator.mosbeau;


import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;


/**
 * Created by Administrator on 9/7/2015.
 */
public class HomeFragment extends Fragment {

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    public HomeFragment () {
    }

    Boolean InternetAvailable = false;
    Seocnd detectconnection;

    ImageView imageView, imageView3;
    ProgressBar progressBar;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.homelayout, container, false);

        detectconnection = new Seocnd(getActivity());
        InternetAvailable = detectconnection.InternetConnecting();
        if (InternetAvailable) {

            imageView = (ImageView) rootView.findViewById(R.id.imageView);
            Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index1.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView);

            imageView3 = (ImageView) rootView.findViewById(R.id.imageView3);
            Glide.with(getActivity()).load("http://joehamirbalabadan.com/android/android/imghome/index3.png").diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.indexloading).into(imageView3);


        } else {
            NointernetFragment fragment = new NointernetFragment();
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.container, fragment)
                    .commit();
        }

        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        ((MainActivity) activity).onSectionAttached(1);
    }

}
Sam Judd
  • 7,317
  • 1
  • 38
  • 38
Joe
  • 227
  • 1
  • 4
  • 18
  • i think problem is with gif file , try using an image for placeholder , see it works or not. – Pirisok Oct 01 '15 at 08:12
  • no problem with the placeholder.. it works but what i want is a loading image.. i know it is not possible to add gif image in the placeholder but i cant find a good code that work for my code. i want a loading before the image result.. – Joe Oct 01 '15 at 08:20

1 Answers1

2

I had same problem. I solved it by using picasso library. find the download link here

and then try this.

ProgressBar spinner = (ProgressBar) findViewById(R.id.loading);
spinner.setVisibility(View.VISIBLE);

Picasso.with(getApplicationContext())
       .load((your URL)
            .into(imageView, new Callback() {
                    @Override
                    public void onSuccess() {
                        spinner.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError() {
                        spinner.setVisibility(View.GONE);
                        imageView
                                .setBackgroundResource(R.drawable.small_logo);
                    }
                });

Here I have wrap ImageView and ProgressBar(spinner in above code) in RelativeLayout.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip" >

<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:scaleType="fitXY" />

<ProgressBar
    android:id="@+id/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone" /></FrameLayout>

hope this helps you.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
  • where is the spinner came from? in this part of your code.. spinner.setVisibility(View.VISIBLE); and also what callback i need to import? – Joe Oct 01 '15 at 08:48
  • spinner is your `ProgressBar` from that XML file. sorry Forgot to change it. – V-rund Puro-hit Oct 01 '15 at 08:54
  • new Callback() show many class to import. what class i need to import? – Joe Oct 01 '15 at 09:15
  • 1
    found this solution.. http://stackoverflow.com/questions/26054420/set-visibility-of-progress-bar-gone-on-completion-of-image-loading-using-glide-l – Joe Oct 01 '15 at 09:33