ashu2121

Untitled

Feb 8th, 2016
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. public class Latest_Product extends BaseAdapter {
  2.  
  3.     // variiables declaration
  4.     View gridView;
  5.     private Context context;
  6.     Function_List lib_function = new Function_List();
  7.     private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();
  8.     private DisplayImageOptions options;
  9.    
  10.     //contsructor
  11.     public Latest_Product(Context c, ArrayList<HashMap<String, String>> json_value) {
  12.         // TODO Auto-generated method stub
  13.         context = c;
  14.         MyArr = json_value;
  15.         Log.d("latest product calling","calling");
  16.    
  17.         TextView product_name;
  18.         TextView product_price;
  19.  
  20.     }
  21.  
  22.  
  23.     public int getCount() {
  24.         // TODO Auto-generated method stub
  25.         Log.d("size of item", "" + MyArr.size());
  26.  
  27.         return MyArr.size();
  28.     }
  29.  
  30.     public Object getItem(int position) {
  31.         // TODO Auto-generated method stub
  32.         return position;
  33.     }
  34.  
  35.     public long getItemId(int position) {
  36.         // TODO Auto-generated method stub
  37.         HashMap<String, String> mapAtPostion = MyArr.get(position);
  38.         return Long.valueOf(MyArr.get(position).get("product_id"));
  39.  
  40.  
  41.     }
  42.  
  43.     public View getView(int position, View convertView, ViewGroup parent) {
  44.         final ViewHolder holder;
  45.         View view = convertView;
  46.         TextView product_name;
  47.         TextView product_price;
  48.  
  49.         LayoutInflater inflater = (LayoutInflater) context
  50.                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  51.  
  52.         if (view == null) {
  53.  
  54.  
  55.             view = inflater.inflate(R.layout.home_best_collection, parent, false);
  56.             holder = new ViewHolder();
  57.             assert view != null;
  58.             ImageView imageView = (ImageView) view.findViewById(R.id.imageView26);
  59.             holder.imageView = (ImageView) view.findViewById(R.id.imageView26);
  60.             holder.progressBar = (ProgressBar) view.findViewById(R.id.progress);
  61.             product_name = (TextView) view.findViewById(R.id.textView21);
  62.             product_price = (TextView) view.findViewById(R.id.textView23);
  63.  
  64.             String name = MyArr.get(position).get("product_name");
  65.             int namelength = name.length();
  66.             if(namelength >= 33)
  67.             {
  68.                 product_name.setText(MyArr.get(position).get("product_name").substring(0,29)+"..."+MyArr.get(position).get("product_id"));
  69.             }
  70.             else{product_name.setText(MyArr.get(position).get("product_name")+MyArr.get(position).get("product_id"));}
  71.             product_price.setText(MyArr.get(position).get("product_price"));
  72.             String product_status = MyArr.get(position).get("product_status");
  73.  
  74.             if(product_status.equals("false"))
  75.             {
  76.  
  77.                 Button add_to_cart = (Button) view.findViewById(R.id.add_to_cart1);
  78.                 add_to_cart.setVisibility(View.GONE);
  79.                 View background_height = (View) view.findViewById(R.id.bestproduct1);
  80.             }
  81.             else
  82.             {
  83.                 Button add_to_cart = (Button) view.findViewById(R.id.add_to_cart1);
  84.                 add_to_cart.setVisibility(View.VISIBLE);
  85.             }
  86.            
  87.             //using picasoo
  88.             Picasso.with(context)
  89.                     .load(MyArr.get(position).get("product_image"))
  90.                     .placeholder(R.drawable.ic_stub) // optional
  91.                     .error(R.drawable.ic_error)         // optional
  92.                     .resize(100, 120)
  93.                     .centerCrop()
  94.                     /*.memoryPolicy(MemoryPolicy.NO_CACHE) /* // to disable cache
  95.                     .into(imageView);
  96.  
  97.  
  98.           //  view.setTag(holder);
  99.         } else {
  100.             holder = (ViewHolder) view.getTag();
  101.         }
  102.  
  103.         return view;
  104.     }
  105.  
  106. }
Add Comment
Please, Sign In to add comment