/** Created by Harshu on 19-10-2015. */ public class Sub_Cat_Adapter extends BaseAdapter { Context context; List<SubCatItem> catItems; ImageLoader imageLoader = AppController.getInstance().getImageLoader(); public Sub_Cat_Adapter(Context context, List<SubCatItem> items) { this.context = context; this.catItems = items; } /*private view holder class*/ private class ViewHolder { NetworkImageView imageView; TextView txtTitle; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); if (convertView == null) { convertView = mInflater.inflate(R.layout.main_cat_list_item, null); holder = new ViewHolder(); holder.txtTitle = (TextView) convertView.findViewById(R.id.tv_title); holder.imageView = (NetworkImageView) convertView.findViewById(R.id.iv_cat_image); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } SubCatItem catItem = (SubCatItem) getItem(position); holder.txtTitle.setText(catItem.getName()); holder.imageView.setImageUrl(catItem.getImage(), imageLoader); holder.txtTitle.setBackgroundResource(R.drawable.lay_bg_corner_common); return convertView; } @Override public int getCount() { return catItems.size(); } @Override public Object getItem(int position) { return catItems.get(position); } @Override public long getItemId(int position) { return catItems.indexOf(getItem(position)); } }
public void Load_Filter(int sub_cat_item) { pDialog = new ProgressDialog(ctx); pDialog.setMessage("Please wait..."); pDialog.setCancelable(false); showpDialog(); favority_item = new ArrayList<Filter_1_Item>(); // products_list=new ArrayList<Product>(); String filter_url = "http://www.vintechdreamlab.com/demo/ttb/protected/getfilter.php?categoryid=" + sub_cat_item; System.out.println("Url ==> " + filter_url); JsonObjectRequest jsonObjReq = new JsonObjectRequest( Request.Method.POST, filter_url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d("Responce ", response.toString()); try { // Parsing json object response // response will be a json object String ResponceMsg = response.getString("ResponseMsg"); int ResponceCode = response.getInt("ResponseCode"); String Result = response.getString("Result"); if (Result.equals("True")) { JSONArray jsonArray = response.getJSONArray("Filters"); for (int k = 0; k < jsonArray.length(); k++) { JSONObject jobj = jsonArray.getJSONObject(k); String name = jobj.getString("name"); JSONArray option_array = jobj.getJSONArray("option"); Filter_1_Item cat = new Filter_1_Item(); cat.setFiltername(name); ArrayList<String> filter_val = new ArrayList<String>(); ArrayList<String> filter_val_count = new ArrayList<String>(); for (int i = 0; i < option_array.length(); i++) { JSONObject jobj_val = option_array.getJSONObject(i); filter_val.add(jobj_val.getString("value")); filter_val_count.add(jobj_val.getString("count")); } cat.setFilter_item(filter_val); cat.setFilter_item_count(filter_val_count); // Toast.makeText(ctx, // name+" "+option_array+"", // Toast.LENGTH_LONG).show(); favority_item.add(cat); } main_adapter = new Filter_1_Adapter(ctx, favority_item); lv_mainactivity.setAdapter(main_adapter); main_adapter.notifyDataSetChanged(); } } catch (JSONException e) { e.printStackTrace(); Toast.makeText(ctx, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } hidepDialog(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d("", "Error: " + error.getMessage()); Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_SHORT).show(); // hide the progress dialog hidepDialog(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(jsonObjReq); }
public void Load_Sub_Cat(int sub_cat_item) { pDialog = new ProgressDialog(ctx); pDialog.setMessage("Please wait..."); pDialog.setCancelable(false); showpDialog(); sub_item_array = new ArrayList<Filter_2_Item>(); // products_list=new ArrayList<Product>(); String sub_url = "http://www.vintechdreamlab.com/demo/ttb/protected/getsubcategoriesfilter.php?categoryid=" + sub_cat_item; System.out.println("Url ==> " + sub_url); JsonObjectRequest jsonObjReq = new JsonObjectRequest( Request.Method.POST, sub_url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d("Responce ", response.toString()); try { // Parsing json object response // response will be a json object String ResponceMsg = response.getString("ResponseMsg"); int ResponceCode = response.getInt("ResponseCode"); String Result = response.getString("Result"); // // Toast.makeText(ctx, ResponceMsg, // Toast.LENGTH_LONG).show(); if (Result.equals("True")) { JSONArray jsonArray = response.getJSONArray("categories"); for (int k = 0; k < jsonArray.length(); k++) { JSONObject jobj = jsonArray.getJSONObject(k); Filter_2_Item dprod = new Filter_2_Item(); dprod.setId(jobj.getInt("categoryid")); dprod.setName(jobj.getString("categoryname")); dprod.setParent_id(jobj.getInt("parentid")); dprod.setChildivailable(jobj.getString("lastchild")); sub_item_array.add(dprod); } sub_adapter = new Filter_2_Adapter(ctx, sub_item_array); lv_subactivity.setAdapter(sub_adapter); sub_adapter.notifyDataSetChanged(); } } catch (JSONException e) { e.printStackTrace(); Toast.makeText(ctx, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } hidepDialog(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d("", "Error: " + error.getMessage()); Toast.makeText(ctx, error.getMessage(), Toast.LENGTH_SHORT).show(); // hide the progress dialog hidepDialog(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(jsonObjReq); }