Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:card_view="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ListView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/cart_list_view"
- android:listSelector="@android:color/transparent"
- android:cacheColorHint="@android:color/transparent">
- </ListView>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- xmlns:card_view="http://schemas.android.com/apk/res-auto"
- android:id="@+id/activity_cart"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.badr.eco.CartActivity">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <ImageView
- android:contentDescription="row"
- android:id="@+id/ImgProduct"
- android:layout_width="150px"
- android:layout_height="150px"
- android:layout_margin="6dp"/>
- <TextView
- android:id="@+id/TitleProduct"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="180px"
- android:textSize="20sp"
- android:layout_marginTop="10dp"
- />
- <TextView
- android:id="@+id/PriceProduct"
- android:layout_below="@id/TitleProduct"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="180px"
- android:layout_marginTop="10dp"
- android:textSize="20sp"
- />
- <ImageView
- android:id="@+id/delete_item_from_cart"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_delete_black_24dp"
- android:layout_alignTop="@+id/PriceProduct"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- </RelativeLayout>
- lic class CartListAdapter extends ArrayAdapter<String> {
- private ImageView img_prdtct;
- private TextView title_prdct;
- private TextView price_prdct;
- private DBHelper Mydb;
- private ImageView Img_delete;
- private Context context;
- private ArrayList<String> My_prdcts_List;
- public CartListAdapter(Context context, int resource, ArrayList<String> objects) {
- super(context, resource, objects);
- this.context = context;
- My_prdcts_List = objects;
- }
- @NonNull
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- LayoutInflater inflater = (LayoutInflater)
- getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View rowView = inflater.inflate(R.layout.activity_cart, parent, false);
- String obj = My_prdcts_List.get(position);
- String [] items = obj.split("/");
- img_prdtct = (ImageView)rowView.findViewById(R.id.ImgProduct);
- title_prdct = (TextView)rowView.findViewById(R.id.TitleProduct);
- price_prdct = (TextView)rowView.findViewById(R.id.PriceProduct);
- Img_delete = (ImageView) rowView.findViewById(R.id.delete_item_from_cart);
- title_prdct.setText(items[0]);
- price_prdct.setText(items[1] + "DH");
- img_prdtct.setImageResource(Integer.parseInt(items[2]));
- //Les evenements
- img_prdtct.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(context, "Clicked",Toast.LENGTH_SHORT).show();
- //Log.d("Clicked", "deleteButton");
- }
- });
- return rowView;
- }
- public class CartActivity extends AppCompatActivity {
- private DBHelper Mydb;
- private ArrayList<String> Array_List;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_cart_main);
- Array_List = new ArrayList<>();
- Mydb = new DBHelper(this);
- Array_List = Mydb.getAllRows("cart");
- CartListAdapter adapter = new CartListAdapter(this,0,Array_List);
- ListView list = (ListView)findViewById(R.id.cart_list_view);
- list.setAdapter(adapter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement