Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:card_view="http://schemas.android.com/apk/res-auto"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7.  
  8. <ListView
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:id="@+id/cart_list_view"
  12. android:listSelector="@android:color/transparent"
  13. android:cacheColorHint="@android:color/transparent">
  14. </ListView>
  15.  
  16. <?xml version="1.0" encoding="utf-8"?>
  17. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  18. xmlns:tools="http://schemas.android.com/tools"
  19. xmlns:card_view="http://schemas.android.com/apk/res-auto"
  20. android:id="@+id/activity_cart"
  21. android:layout_width="match_parent"
  22. android:layout_height="match_parent"
  23. android:paddingBottom="@dimen/activity_vertical_margin"
  24. android:paddingLeft="@dimen/activity_horizontal_margin"
  25. android:paddingRight="@dimen/activity_horizontal_margin"
  26. android:paddingTop="@dimen/activity_vertical_margin"
  27. tools:context="com.example.badr.eco.CartActivity">
  28.  
  29. <RelativeLayout
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content">
  32.  
  33. <ImageView
  34. android:contentDescription="row"
  35. android:id="@+id/ImgProduct"
  36. android:layout_width="150px"
  37. android:layout_height="150px"
  38. android:layout_margin="6dp"/>
  39.  
  40. <TextView
  41. android:id="@+id/TitleProduct"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_marginLeft="180px"
  45. android:textSize="20sp"
  46. android:layout_marginTop="10dp"
  47. />
  48. <TextView
  49. android:id="@+id/PriceProduct"
  50. android:layout_below="@id/TitleProduct"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:layout_marginLeft="180px"
  54. android:layout_marginTop="10dp"
  55. android:textSize="20sp"
  56. />
  57.  
  58. <ImageView
  59. android:id="@+id/delete_item_from_cart"
  60. android:layout_width="wrap_content"
  61. android:layout_height="wrap_content"
  62. android:src="@drawable/ic_delete_black_24dp"
  63. android:layout_alignTop="@+id/PriceProduct"
  64. android:layout_alignParentRight="true"
  65. android:layout_alignParentEnd="true" />
  66. </RelativeLayout>
  67.  
  68. lic class CartListAdapter extends ArrayAdapter<String> {
  69.  
  70. private ImageView img_prdtct;
  71. private TextView title_prdct;
  72. private TextView price_prdct;
  73. private DBHelper Mydb;
  74. private ImageView Img_delete;
  75.  
  76. private Context context;
  77. private ArrayList<String> My_prdcts_List;
  78.  
  79. public CartListAdapter(Context context, int resource, ArrayList<String> objects) {
  80. super(context, resource, objects);
  81. this.context = context;
  82. My_prdcts_List = objects;
  83. }
  84.  
  85. @NonNull
  86. @Override
  87. public View getView(int position, View convertView, ViewGroup parent) {
  88.  
  89. LayoutInflater inflater = (LayoutInflater)
  90. getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  91.  
  92. View rowView = inflater.inflate(R.layout.activity_cart, parent, false);
  93.  
  94. String obj = My_prdcts_List.get(position);
  95. String [] items = obj.split("/");
  96.  
  97. img_prdtct = (ImageView)rowView.findViewById(R.id.ImgProduct);
  98. title_prdct = (TextView)rowView.findViewById(R.id.TitleProduct);
  99. price_prdct = (TextView)rowView.findViewById(R.id.PriceProduct);
  100. Img_delete = (ImageView) rowView.findViewById(R.id.delete_item_from_cart);
  101.  
  102. title_prdct.setText(items[0]);
  103. price_prdct.setText(items[1] + "DH");
  104. img_prdtct.setImageResource(Integer.parseInt(items[2]));
  105.  
  106. //Les evenements
  107. img_prdtct.setOnClickListener(new View.OnClickListener() {
  108. @Override
  109. public void onClick(View v) {
  110. Toast.makeText(context, "Clicked",Toast.LENGTH_SHORT).show();
  111. //Log.d("Clicked", "deleteButton");
  112. }
  113. });
  114. return rowView;
  115. }
  116.  
  117. public class CartActivity extends AppCompatActivity {
  118.  
  119. private DBHelper Mydb;
  120. private ArrayList<String> Array_List;
  121.  
  122. @Override
  123. protected void onCreate(Bundle savedInstanceState) {
  124. super.onCreate(savedInstanceState);
  125. setContentView(R.layout.activity_cart_main);
  126.  
  127. Array_List = new ArrayList<>();
  128. Mydb = new DBHelper(this);
  129. Array_List = Mydb.getAllRows("cart");
  130.  
  131. CartListAdapter adapter = new CartListAdapter(this,0,Array_List);
  132.  
  133. ListView list = (ListView)findViewById(R.id.cart_list_view);
  134. list.setAdapter(adapter);
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement