title: How to store items of multiple JSON Array and display it listview?
body: <p>In my application I am using listview and I am also doing json parsing.</p>
  
  <p>Now the issue is I want to set colors in my views, the color code I am getting from server.</p>
  
  <p>Following is my json response and java code can any one help me, to set color codes in my views?</p>
  
  <pre><code>[
      {
          "id_product": "1445",
          "name": "Stylish Sleeveless Leather Vest",
          "price": 1990,
          "discount": 199,
          "colors": [
              "#000000",
              "#7E3517",
              "#C85A17"
          ],
          "sizes": [
              "Medium",
              "Large",
              "Small"
          ],
          "img_url": "",
          "popup_images": [
  
          ]
      },
      {
          "id_product": "1427",
          "name": "Stylish Slim Fit Designed PU Leather Jacket",
          "price": 3290,
          "discount": 329,
          "colors": [
              "#000000",
              "#C85A17"
          ],
          "sizes": [
              "Large",
              "Medium",
              "Small"
          ],
          "img_url": "",
          "popup_images": [
  
          ]
      }
  ]
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class Product_Listing extends Fragment{
  
      private ListView listview;
  
  
      private ArrayList&lt;HashMap&lt;String,String&gt;&gt; aList;
      private static String INTEREST_ACCEPT_URL = "";
     // private static final String INTEREST_ACCEPT="interestaccept";
      private static final String INTERESTACCEPT_USER_NAME="name";
      private static final String INTEREST_ACCEPT_PRICE="price";
      private static final String INTEREST_ACCEPT_PRODUCTID="id_product";
     private static final String INTEREST_ACCEPT_DISCOUNT="discount";
      private static final String INTEREST_ACCEPT_IMAGEURL="img_url";
      private static final String INTEREST_ACCEPT_COLOR="colors";
      private static final String INTEREST_ACCEPT_SIZES="sizes";
      private CustomAdapterAccept adapter;
  
  
      private String brandnms;
      String user_img;
      ArrayList&lt;String&gt; userImgArrayList;
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
           View rootView = inflater.inflate(R.layout.product_listing_listivew, container, false);
  
  
           Bundle bundle = this.getArguments();
              brandnms = bundle.getString("Brandkeyword");
           listview=(ListView)rootView.findViewById(R.id.listview_productlistings);
  
              INTEREST_ACCEPT_URL = "";
  
              new LoadAlbums().execute();
  
           return rootView;
      }
  
      public class CustomAdapterAccept extends BaseAdapter{
  
          private Context context;
          private ArrayList&lt;HashMap&lt;String,String&gt;&gt; listData;
          private AQuery aQuery;
          String rup="\u20B9";
          private static final String TAG_NAME="name";
         private static final String TAG_IMAGE="img_url";
          private static final String TAG_PRICE="price";
  
  
          public CustomAdapterAccept(Context context,ArrayList&lt;HashMap&lt;String,String&gt;&gt; listData) {
              this.context = context;
              this.listData=listData;
              aQuery = new AQuery(this.context);
          }
  
          @Override
          public int getCount() {
              return listData.size();
          }
  
          @Override
          public Object getItem(int position) {
              return listData.get(position);
          }
  
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(final int position, View convertView, ViewGroup parent) {
              ViewHolder holder;
              if (convertView == null) {
                  holder = new ViewHolder();
                  convertView = LayoutInflater.from(context).inflate(R.layout.product_listing_items, null);
                 holder.propic = (ImageView) convertView.findViewById(R.id.productlist_img);
                  holder.txtproname = (TextView) convertView.findViewById(R.id.productlist_name);
                  holder.txtprice = (TextView) convertView.findViewById(R.id.productlist_price);
                 // holder.txtpr = (TextView) convertView.findViewById(R.id.productlist_name);
  
  
                  convertView.setTag(holder);
              }else{
                  holder = (ViewHolder) convertView.getTag();
              }
              holder.txtproname.setText(listData.get(position).get(TAG_NAME));
              holder.txtprice.setText(listData.get(position).get(TAG_PRICE));
  
  
              aQuery.id(holder.propic).image(listData.get(position).get(TAG_IMAGE),true,true,0,R.drawable.meracaslogo);
  
              // image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image
              return convertView;
          }
          class ViewHolder{
              TextView txtprice;
              ImageView propic;
              TextView txtproname;
          }
  
      }
      class LoadAlbums extends AsyncTask&lt;String, String, ArrayList&lt;HashMap&lt;String,String&gt;&gt;&gt; {
          private ProgressDialog pDialog;
          private String first;
          private String sizefirst;
          private JSONObject c;
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(getActivity());
              pDialog.setMessage("Loading...");
              pDialog.setIndeterminate(true);
             // pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress));
              pDialog.setCancelable(false);
              pDialog.show();
          }
          protected ArrayList&lt;HashMap&lt;String,String&gt;&gt; doInBackground(String... args) {
              ServiceHandler sh = new ServiceHandler();
              // Making a request to url and getting response
              ArrayList&lt;HashMap&lt;String,String&gt;&gt; data = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
              String jsonStr = sh.makeServiceCall(INTEREST_ACCEPT_URL, ServiceHandler.GET);
  
              Log.d("Response: ", "&gt; " + jsonStr);
  
              if (jsonStr != null) {
                  try {
                      JSONArray jsonary = new JSONArray(jsonStr);
  
                      System.out.println("Test jsonObj"+jsonary);
  
                      // Getting JSON Array node
                    // interestaccept = jsonObj.getJSONArray(INTEREST_ACCEPT);
  
                      for (int i = 0; i &lt; jsonary.length(); i++) {
                          c = jsonary.getJSONObject(i);
                          // creating new HashMap
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                          // adding each child node to HashMap key =&gt; value
                          map.put(INTERESTACCEPT_USER_NAME, c.getString(INTERESTACCEPT_USER_NAME));
                          map.put(INTEREST_ACCEPT_PRICE,c.getString(INTEREST_ACCEPT_PRICE));
                          map.put(INTEREST_ACCEPT_DISCOUNT, c.getString(INTEREST_ACCEPT_DISCOUNT));
                          map.put(INTEREST_ACCEPT_PRODUCTID, c.getString(INTEREST_ACCEPT_PRODUCTID));
                          map.put(INTEREST_ACCEPT_IMAGEURL, c.getString(INTEREST_ACCEPT_IMAGEURL));
                          //map.put(INTEREST_ACCEPT_AGE, c.getString(INTEREST_ACCEPT_AGE)+" years");
                          //map.put(INTEREST_ACCEPT_LOCATION, c.getString(INTEREST_ACCEPT_LOCATION));
                          // adding HashList to ArrayList
  
                          JSONArray colors=c.getJSONArray(INTEREST_ACCEPT_COLOR);
                          JSONArray sizes=c.getJSONArray(INTEREST_ACCEPT_SIZES);
  
                          user_img=c.getString(INTEREST_ACCEPT_COLOR);
  
                         // user_img=jsonObj.getString(USER_IMG);
  
  
                          user_img = "";
                          userImgArrayList = new ArrayList&lt;String&gt;();//declare userImgArrayList globally like ArrayList&lt;String&gt; userImgArrayList;
                          JSONArray picarray = c.getJSONArray(INTEREST_ACCEPT_COLOR);
                          for(int a=0;a&lt; picarray.length();a++)
                          {
                              user_img = picarray.getString(a);
                              userImgArrayList.add(user_img);
                          }
                          Log.d("mylog", "curent  pro pic  = " + userImgArrayList);
  
                          first=userImgArrayList.get(i);
                          System.out.println("Color First"+first);
  
                          //first=colors.getJSONObject(a);
  
                         /* for(int j=0;j&lt;colors.length();j++)
                          {
                              //first=colors.getJSONObject(j);
  
                          }
  
                          for(int s=0;s&lt;sizes.length();s++)
                          {
                              sizefirst=sizes.getString(s);
                          }
                          System.out.println("Color First"+first);
  
                          System.out.println("Colors"+colors);*/
                          data.add(map);
                      }
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              } else {
                  Log.e("ServiceHandler", "Couldn't get any data from the url");
              }
              return data;
          }
          protected void onPostExecute(ArrayList&lt;HashMap&lt;String,String&gt;&gt; result) {
              super.onPostExecute(result);
  
              // dismiss the dialog after getting all albums
              if (pDialog.isShowing())
                  pDialog.dismiss();
              // updating UI from Background Thread
                  aList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
                  aList.addAll(result);
                  adapter = new CustomAdapterAccept(getActivity(),result);
                  listview.setAdapter(adapter);
                  adapter.notifyDataSetChanged();
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>listitem</p>
  
  <pre><code> &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="25dp"
          android:layout_marginTop="10dp"
          android:orientation="horizontal" &gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:text="Colors:" /&gt;
  
          &lt;TextView
              android:id="@+id/firstcolor"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="7dp"
               /&gt;
  
          &lt;TextView
              android:id="@+id/secondcolor"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
               /&gt;
  
          &lt;TextView
              android:id="@+id/thirdcolor"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
               /&gt;
  
          &lt;TextView
              android:id="@+id/fourthcolor"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
               /&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mFBX4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mFBX4.png" alt="enter image description here"></a></p>