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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:33:52+00:00 2026-05-23T22:33:52+00:00

Ok so after making lots of progress over the weekend I am getting stuck

  • 0

Ok so after making lots of progress over the weekend I am getting stuck on the gridView and ImageAdapter. Up to now all I have done is my main activity gets the user selected tags, does a query and returns json_ecoded data. I pass the json data via bundle and intent to my showThumb activity. This activity is supposed to attach an ImageAdapter to my grid view. But I cant figure out how to pass my json data to the ImageAdapter and then use the data from json to supply the paths to my thumbnails.

If there is any advice I can get to help that would be amazing.

JSON Data:

{"id":["1","2","3"],"name":["Dragon","Butterfly","Tattoo"],"thumb":["thm_polaroid.jpg","thm_default.jpg","thm_enhanced-buzz-9667-1270841394-4.jpg"],"path":["polaroid.jpg","default.jpg","enhanced-buzz-9667-1270841394-4.jpg"]}

ShowThumb Class

package com.flash_Images;

import android.os.Bundle;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class showThumb extends Activity{



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gridlayout);

            Bundle bundle = getIntent().getExtras();
         String jsonData = bundle.getString("jsonData");

         try {
            JSONObject jsonObj = new JSONObject(jsonData);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

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

ImageAdapter Class:

package com.flash_Images;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    private JSONObject jsonObj;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public ImageAdapter(showThumb c) {
        // TODO Auto-generated constructor stub
    }

    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;
        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;
    }


    JSONArray menuitemArr = popupObject.getJSONArray("thumb");


    // references to our images
    private Integer[] mThumbIds = {


//I need to loop through my json "thumb:"  items below to add the image paths for the grid view

            for (int i = 0; i < menuitemArr.length(); i++) {
                // printing the values to the logcat
                setImageDrawable(Drawable.createFromPath(myFooArray[position].thumb);
            }

            //This is the example data I need to replace
           /** R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7,
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7,
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7*/
    };
}
  • 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-23T22:33:52+00:00Added an answer on May 23, 2026 at 10:33 pm

    Use an ArrayAdapter instead of BaseAdapter to make things work.

    Make a class of menuitemArr so that they can consist the data returned from json parser.

    Define an ArrayAdapter like this

    public class ImageAdapter extends ArrayAdepter<YOUNEWCLASS>

    create a constructor where you can pass the list of the parsed data

    Take a look at the example of a ArrayAdapter here.

    Now use the adapter like this

    GridView gridview = (GridView) findViewById(R.id.gridview);
            gridview.setAdapter(new ImageAdapter(this,listofYourNewCalss));
    

    Hope this can help you.

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

Sidebar

Related Questions

I'm now making unit-tests for already existing code. I faced the next problem: After
I have realised after making about 20 tables that I need to user utf8_unicode
I have an java program that runs external programs executing commandline parameters. After making
I have a system where clients can make orders. After making order they have
If I want to resubmit changes, do I have to redefine them after making
I have install the C/C++ CDT Version of Eclipse. After making a HelloWorld.c file
I have install the C/C++ CDT Version of Eclipse. After making a HelloWorld.c file
After making any change on controllers I have to rebuild for the changes to
After making some research, I now know that I can launch an iphone app
I've been getting an 'Invalid JSON' after making a jQuery AJAX Request. This request

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.