Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:41:48+00:00 2026-06-03T22:41:48+00:00

I am trying to display images in a grid view within a fragment, and

  • 0

I am trying to display images in a grid view within a fragment, and the images are downloaded on the run time within an async task loader and I am using the base adapter within the same fragment.

Now, everything is working fine except that while the images are loaded but no loader animation is shown. My Fragment class is as under which contains a BaseAdapter and AsyncLoader

package friends.appModules.mainClasses;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import friends.appModules.commonClasses.Cheeses;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

public class PeopleNearYou extends Fragment implements     LoaderManager.LoaderCallbacks<List<Images>>{

private GridView pnuGridView;
ImageAdapter myImageAdapter;
boolean isLoadFinished = false;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d("Where am I?", "in onActivityCreated PeopleNearYou");

    getLoaderManager().initLoader(1, null, this);
}

/* First Method call after onActivityCreated*/
@Override
public Loader<List<Images>> onCreateLoader(int id, Bundle args) {
    Log.d("Where am I?", "in onCreateLoader PeopleNearYou");
    return new PeopleNearYouLoader(getActivity());
}


@Override
/*Fourth Method Called*/
public void onLoadFinished(Loader<List<Images>> loader,
        List<Images> data) {
    Log.d("Where am I?", "in onLoadFinished PeopleNearYou");

    final Context c = this.getActivity().getApplicationContext();
    myImageAdapter = new ImageAdapter(c);

    myImageAdapter.setData(data);

    pnuGridView.setAdapter(myImageAdapter);
}

@Override
public void onLoaderReset(Loader<List<Images>> loader) {
    Log.d("Where am I?", "in onLoaderReset PeopleNearYou");
    myImageAdapter.setData(null);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    Log.d("Where am I?", "in onCreateView PeopleNearYou");

    View view = inflater.inflate(R.layout.people_near_you, container, false);

    pnuGridView = (GridView) view.findViewById(R.id.gridview);
    //pnuGridView.setBackgroundColor(R.color.dark_gry_txt);
    return view;
}



public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

public class ImageAdapter extends BaseAdapter{
    private Context mContext;
    private List<Images> finallyListCreated;

    public ImageAdapter(Context c) {
        Log.d("Where am I?", "in ImageAdapter Constructor PeopleNearYou");
        mContext = c;

        pnuGridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(mContext, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public int getCount() {
        Log.d("Where am I?", "in getCount PeopleNearYou");
        return 20;
    }

    public Object getItem(int position) {
        Log.d("Where am I?", "in getItem PeopleNearYou");
        return null;
    }

    public long getItemId(int position) {
        Log.d("Where am I?", "in getItemId PeopleNearYou");
        return 0;
    }

    public void setData(List<Images> data) {
        Log.d("Where am I ??", "in onSetData() PeopleNearYou");
        if (data != null) {
            finallyListCreated = data;
        }
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d("Where am I?", "in getView PeopleNearYou");
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
            imageView.setBackgroundColor(R.color.dark_gry_txt);
        } else {
            imageView = (ImageView) convertView;
        }

        Images item = finallyListCreated.get(position);
        imageView.setImageDrawable(item.getImageUrl());
        return imageView;
    }
}

public static class PeopleNearYouLoader extends AsyncTaskLoader<List<Images>>{

    Context loaderContext;
    List<Images> loaderImageList;

    public PeopleNearYouLoader(Context context) {
        super(context);
        Log.d("Where am I?", "in PeopleNearYouLoader Constructor PeopleNearYou");
        loaderContext = context;
    }

    @Override
    /*Third method called if there are no images in the list else Deliver Result method will be called*/
    public List<Images> loadInBackground() 
    {
        Log.d("Where am I ??", "in loadInBackground() PeopleNearYou");

        List<Images> peopleNearYouImagesList = new ArrayList<Images>(20);

        for (int i=0; i<20; i++) {
            Log.d("Where am I ??", "For loop to set Image objects PeopleNearYou");
            Images peopleNearYouImages = new Images(loadImageFromUrl(Cheeses.imageUrls[i]));
            peopleNearYouImagesList.add(peopleNearYouImages);
        }

        return peopleNearYouImagesList;
    }

    @Override
    public void onCanceled(List<Images> data) {
        super.onCanceled(data);
        onReleaseResources(data);
    }

    @Override
    public void deliverResult(List<Images> images) {
        if (isReset()) {
            if (images != null) {
                onReleaseResources(images);
            }
        }

        List<Images> oldImages = images;
        loaderImageList = images;

        if (isStarted()) {
            super.deliverResult(images);
            Log.d("Where am I ??", "in isStarted = true PeopleNearYou");
        }

        if (oldImages != null) {
            onReleaseResources(oldImages);
            Log.d("Where am I ??", "in oldImages != null PeopleNearYou");
        }
    }

    @Override
    /* Second method called*/
    protected void onStartLoading() {
        if (loaderImageList != null) {
            deliverResult(loaderImageList);
            Log.d("Where am I ??", "in onStartLoading() and list is not null");
        }
        else {
            Log.d("Where am I ??", "in onStartLoading() and list is null");
            forceLoad();
        }
    }

    @Override
    protected void onStopLoading() {
        cancelLoad();
        Log.d("Where am I ??", "in onStopLoading() PeopleNearYou");
    }

    @Override
    protected void onReset() {
        super.onReset();

        onStopLoading();

        if (loaderImageList != null) {
            onReleaseResources(loaderImageList);
            loaderImageList = null;
        }
    }

    protected void onReleaseResources(List<Images> data) {
        Log.d("Where am I ??", "in onReleaseResources() PeopleNearYou");
    }

    public Drawable loadImageFromUrl(String url) {
        InputStream inputStream;
        try {
            inputStream = new URL(url).openStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return Drawable.createFromStream(inputStream, "src");
    }

}
}

and My gridview layout is:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:columnWidth="90dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
/>

Also the images class used in my code is:

package friends.appModules.mainClasses;

import android.app.Application;
import android.graphics.drawable.Drawable;

public class Images extends Application{
    private Drawable imageUrl;

    public Images(Drawable imageUrl) {
        this.imageUrl = imageUrl;
    }
    public Drawable getImageUrl() {
        return imageUrl;
    }
}

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:41:49+00:00Added an answer on June 3, 2026 at 10:41 pm

    Take a look at the source code for ListFragment.setListShown(). It does exactly what you’re looking for with the GridView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to sort images using: http://jqueryui.com/demos/sortable/display-grid.html And then somehow submit the newly sorted
I'm trying to display images using my web application written in Rails. I've come
Hi everyone I'm trying to display some images using a GridView. However I'm getting
I am trying to create a grid view by using a UITableView (my older
I'm trying to dynamically align images center within a grid type format. Each image
i am trying to display image using GridView. This is the first time i
I'm trying to download images and display them in a 5x5 grid, and I
I'm creating a grid of thumbnail images, using a UITableView where each cell display
From any specific Post, I am trying to display all images, with their corresponding
I'm trying to display some large images with HTML img tags. At the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.