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

  • Home
  • SEARCH
  • 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 6147791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:09:56+00:00 2026-05-23T19:09:56+00:00

I started with Google’s sample code for a Grid View but how would I

  • 0

I started with Google’s sample code for a Grid View but how would I choose which images show up? Say one time I just wanted eq1 and eq4 to show up, but another time I wanted eq3, eq 6, and eq12 to show up, what do I need to do to the code? The Integer array contains some integers from another part of the app that won’t be the same all the time, and I’m trying to get those to correspond with which images are in the Grid.

public class ImageAdapter extends BaseAdapter {
private Context mContext;
private int length;
private Integer[] choices;

public ImageAdapter(Context c, int inLength, Integer[] inChoices) {
    mContext = c;
    length = inLength;
    choices = inChoices;
}

public int getCount() {
    return length;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {


    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(200, 50));
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);

    return imageView;

}

// references to our images
private Integer[] mThumbIds = {
        R.drawable.eq1, R.drawable.eq2,
        R.drawable.eq3, R.drawable.eq4,
        R.drawable.eq5, R.drawable.eq6,
        R.drawable.eq7, R.drawable.eq8,
        R.drawable.eq9, R.drawable.eq10,
        R.drawable.eq11, R.drawable.eq12,
        R.drawable.eq13, R.drawable.eq14,
        R.drawable.eq15, R.drawable.eq16,
        R.drawable.eq17, R.drawable.eq18,
        R.drawable.eq19, R.drawable.eq20,
        R.drawable.eq21, R.drawable.eq22
};

}

  • 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-05-23T19:09:57+00:00Added an answer on May 23, 2026 at 7:09 pm

    The way this works is that the view calls ImageAdapter.getCount to determine how many images should be displayed, and then it calls ImageAdapter.getView for each position (0, 1, …, up to getCount()-1). So if you just want to show eq1 and eq4, getCount should return 2 and then in getView you’ll have to replace the line

    imageView.setImageResource(mThumbIds[position]);
    

    with something that knows which mThumbIds elements you want. This is really dependent on how you decide which images should be displayed. Often you would just recreate mThumbIds with just the elements you want, but if you wanted another layer of indirection, you could try something like this:

    // This will give you eq1 and eq4
    private Integer[] mActiveImages = {0, 3};
    
    public int getCount() {
        return mActiveImages.length;
    }
    

    and replace that one line in getView with:

    imageView.setImageResource(mThumbIds[mActiveImages[position]]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started using subversion for one of my projects and it would be absolutely
Is there any good article that gets me started with Google Visualization API which
I started to list my markers individually for my Google Map, but quickly realised
hi I started learning google data api. I have one question What will be
Finally, I find some article in http://code.google.com/intl/en/web/ajaxcrawling/docs/getting-started.html msnbc use this method. Thanks for all
Google has started crawling my site, but from a temporary domain (beta.mydomain instead of
Have just started using Google Chrome , and noticed in parts of our site,
I have recently started looking into Google Charts API for possible use within the
I started an application in Google App Engine right when it came out, to
We started using Google Maps on our web application rather extensively. It worked fine

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.