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 8894805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:36:02+00:00 2026-06-14T23:36:02+00:00

I am using the sample ImageAdpater provided in the google documentation to populate a

  • 0

I am using the sample ImageAdpater provided in the google documentation to populate a gridview with drawables. What I’m trying to do is populate the gridview with an array of drawables in an xml file.

I use TypedArray imgs = getResources().obtainTypedArray(R.array.log_type_icons); to access the array from my main activity, but that doesn’t work within the ImageAdapter class.

The array:

<string-array name="log_type_icons">
    <item>@drawable/ic_launcher</item>
    <item>@drawable/ic_headache</item>
    <item>@drawable/ic_man</item>
    <item>@drawable/ic_woman</item>
    <item>@drawable/ic_kneel</item>
</string-array>

The working ImageAdapter:

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;

}

public int getCount() {
    return mThumbIds.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;
    Log.i("log tag", "gotten resources: " + mThumbIds);
    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);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images
private Integer[] mThumbIds = { R.drawable.ic_headache,
        R.drawable.ic_kneel, R.drawable.ic_man, R.drawable.ic_woman,
        R.drawable.ic_launcher };
}

I know I could manually add the drawable references to the Integer array, but I reference the xml array from my main activity as well, so it would be ideal to be able to add to the xml and not have to change the code.
Does anyone have any insight into this? Am I doing something wrong or missing Something obvious?

Any help would be appreciated,
Thank you

  • 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-14T23:36:03+00:00Added an answer on June 14, 2026 at 11:36 pm

    I ended up solving this problem by using ‘getResources().obtainTypedArray(R.array.log_type_icons);’ to get the array in my main activity, then passed it to the image adapter instead of using ‘getResources()’ within the adapter

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

Sidebar

Related Questions

I'm reading this google guide and using this sample code provided by google ,
I am trying to interate through the below xml sample using XPathNodeIterator nodes =
Using the sample app provided in the android download, I would like to use
I am using the sample provided here and have used the code inside a
I'm using Array.sample to return a random element from an array. I want to
I'm trying to run the Using IndexedDB sample code on https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB Right out of
i am trying to send MMS using code sample from here . I am
I am developing a sample using silverlight and prism. I am trying to create
I am trying out a sample using deployment catalog. I have downloaded a sample
I'm trying to draw a textured quad in XNA using the sample code from

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.