Advertisement
Guest User

Untitled

a guest
Jan 19th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. package com.xyron.galeriashop;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.content.Context;
  6. import android.os.AsyncTask;
  7. import android.util.Log;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.view.ViewGroup;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.ImageView;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16.  
  17. public class ProductItemAdapter extends ArrayAdapter<Product> {
  18. private ArrayList<Product> items;
  19. Context context;
  20. boolean reset = false;
  21. boolean noCarts = false;
  22.  
  23. public ProductItemAdapter(Context context, int textViewResourceId,
  24. ArrayList<Product> items) {
  25. super(context, textViewResourceId, items);
  26. this.items = items;
  27. this.context = context;
  28. }
  29.  
  30. @Override
  31. public View getView(final int position, View convertView, ViewGroup parent) {
  32. View v = convertView;
  33. if (v == null) {
  34. LayoutInflater vi = (LayoutInflater) context
  35. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  36. v = vi.inflate(R.layout.list_row, null);
  37. }
  38. final Product item = items.get(position);
  39. if (item != null) {
  40. final TextView list_product_name = (TextView) v
  41. .findViewById(R.id.list_product_name); //Product_price_field
  42. final TextView list_product_description = (TextView) v
  43. .findViewById(R.id.list_product_description);
  44. final ImageView list_product_thumbnail = (ImageView) v
  45. .findViewById(R.id.list_image);
  46. final ImageView list_add_cart = (ImageView) v
  47. .findViewById(R.id.list_add_cart);
  48. final TextView Product_price_field = (TextView) v
  49. .findViewById(R.id.Product_price_field);
  50.  
  51.  
  52. if (list_product_name != null) {
  53. list_product_name.setText(item.name);
  54. }
  55.  
  56. if (Product_price_field != null) {
  57. Product_price_field.setText(item.price);
  58. Log.d("ITEM", "PREIS: " + item.price);
  59. }
  60.  
  61. if (list_product_description != null) {
  62. list_product_description.setText(item.manuName);
  63. }
  64. if (list_product_thumbnail != null && item.thumb != null) {
  65. list_product_thumbnail.setImageDrawable(item.thumb);
  66. }
  67. if (list_add_cart != null) {
  68. list_add_cart.setImageResource(R.drawable.ic_warenkorb);
  69. }
  70. if (list_add_cart != null && (item.NoCart || noCarts)) {
  71. list_add_cart.setImageResource(R.drawable.empty);
  72. }
  73. list_add_cart.setOnClickListener(new OnClickListener() {
  74. @Override
  75. public void onClick(View v) {
  76. item.setCategory(Globals.selected_category);
  77. Globals.shopCon.add_to_cart(item);
  78. Toast.makeText(context, "Zum Warenkorb hinzugefĆ¼gt", Toast.LENGTH_SHORT).show();
  79. if (list_add_cart != null) {
  80. list_add_cart.setImageResource(R.drawable.ic_warenkorb_filled);
  81. }
  82. class pic extends AsyncTask<Void, Void, Void>{
  83. @Override
  84. protected Void doInBackground(Void... nothing){
  85. try {
  86. Thread.sleep(1000);
  87. } catch (InterruptedException e) {
  88. e.printStackTrace();
  89. }
  90. return null;
  91. }
  92. protected void onPostExecute(Void v){
  93. if (list_add_cart != null) {
  94. list_add_cart.setImageResource(R.drawable.ic_warenkorb);
  95. }
  96. }
  97. }
  98. new pic().execute();
  99. }
  100. });
  101. }
  102. return v;
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement