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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:57:33+00:00 2026-06-19T01:57:33+00:00

How to parsed JSON data from AsyncTask to custom Gridview inside Detail Fragment ?

  • 0

How to parsed JSON data from AsyncTask to custom Gridview inside Detail Fragment ?
I have Integer[] picture , String[] menu and String[] price

in GridView i have 1 ImageView and 2 TextView

    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(mContext);
        pDialog.setMessage("Loading products. Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting All products from url
     * */
    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("All Menu: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);
            System.out.println(success);
            if (success == 1) {
                // products found
                // Getting Array of Products
                menuresto = json.getJSONArray(TAG_MENU);

                // looping through All Products
                for (int i = 0; i < menuresto.length(); i++) {
                    JSONObject c = menuresto.getJSONObject(i);

                    // Storing each json item in variable
                    String name = c.getString(TAG_NAME);
                    String price = c.getString(TAG_PRICE);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_NAME, name);
                    map.put(TAG_PRICE, price);

                    // adding HashList to ArrayList
                    menuList.add(map);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * How to parsed JSON data into GridView
                 * */

            }
        });

    }

Should i work in GetView ?

EDIT
Code Complete of Adapter

public class MyAdapter extends BaseAdapter {

Context mContext;
private ProgressDialog pDialog;
// creating json parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> menuList;

static final String TAG_SUCCESS = "success";
static final String TAG_MENU = "menu";
static final String TAG_MID = "mid";
static final String TAG_NAME = "name";
static final String TAG_PICT = "picture";
static final String TAG_PRICE = "price";

// url to get all menu list
private static String url = "http://10.0.2.2/menu/food/get_all_products.php";

// menu JSONArray
JSONArray menuresto = null;

public Integer[] menupict = { R.drawable.ic_launcher,
        R.drawable.ic_launcher, R.drawable.ic_launcher,
        R.drawable.ic_launcher, R.drawable.ic_launcher,
        R.drawable.ic_launcher, R.drawable.ic_launcher };

private LayoutInflater mInflater;

public MyAdapter(Context c) {

    mContext = c;
    mInflater = LayoutInflater.from(c);
    // array menu
    menuList = new ArrayList<HashMap<String, String>>();

    // Loading products in Background Thread
    new LoadAllProducts().execute();

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return menuList.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return menuList.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    // Building Parameters
    // System.out.println("MyAdapter.getView()");
    ViewHolder holder = null;

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.gviewfill, parent, false);
        holder = new ViewHolder();
        /*
         * holder.ImgView = new ImageView(mContext);
         * holder.ImgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
         * 
         * holder.ImgView = (ImageView) convertView
         * .findViewById(R.id.iv_menu_image);
         */
        holder.txtName = (TextView) convertView
                .findViewById(R.id.tv_menu_name);
        holder.price = (TextView) convertView
                .findViewById(R.id.tv_menu_price);

        if (position == 0) {
            convertView.setTag(holder);
        }
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // holder.ImgView.setImageResource(menupict[position]);
    holder.price.setText("Rp. " + menuList.get(position).get(TAG_PRICE));
    holder.txtName.setText(menuList.get(position).get(TAG_NAME));

    return convertView;
}

static class ViewHolder {
    ImageView ImgView;
    TextView txtName;
    TextView price;
}

/**
 * Background Async Task to Load all product by making HTTP Request
 * */
class LoadAllProducts extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(mContext);
        pDialog.setMessage("Loading products. Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting All products from url
     * */
    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("All Menu: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);
            System.out.println(success);
            if (success == 1) {
                // products found
                // Getting Array of Products
                menuresto = json.getJSONArray(TAG_MENU);

                // looping through All Products
                for (int i = 0; i < menuresto.length(); i++) {
                    JSONObject c = menuresto.getJSONObject(i);

                    // Storing each json item in variable
                    String name = c.getString(TAG_NAME);
                    String price = c.getString(TAG_PRICE);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_NAME, name);
                    map.put(TAG_PRICE, price);

                    // adding HashList to ArrayList
                    menuList.add(map);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */

            }
        });

    }

}

}

  • 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-19T01:57:35+00:00Added an answer on June 19, 2026 at 1:57 am

    How to parsed JSON data into GridView

    => You just need to create an adapter to display data in GridView. Because you are already having ArrayList ready (in terms of menuList) inside doInBackground() of AsyncTask.

    Now, it depends how do you want to display data in GridView, i mean type of item layout you want to display inside GridView.

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

Sidebar

Related Questions

I want a method that extracts the data from a JSON-object parsed before as
I have a flash file which loads data from JSON and parses it. It
I have a UITableView which is populated with some parsed JSON twitter data. The
I have a PHP script that outputs JSON data which is parsed by Javascript
I am getting DataTables warning: JSON data from server could not be parsed. This
Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
I parsed data from json to corresponding class data and them want to save
I'm trying to load and parse json data from an external source into a
... // result is a JSON data passed to this function from outside var

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.