Silicon Valley Mall 6-Shopping Cart editing implementation, Silicon Valley Mall 6-shopping cart

Source: Internet
Author: User

Silicon Valley Mall 6-Shopping Cart editing implementation, Silicon Valley Mall 6-shopping cart

Completion status editing status

1 _ set click events and definition status

In the GovaffairPager class

Public class GovaffairPager extends BasePager {............ /*** edit status */private static final int ACTION_EDIT = 0;/***** completion status */private static final int ACTION_COMPLETE = 1; @ Override public void initData () {...... // set the edit Click Event btn_cart.setTag (ACTION_EDIT); btn_cart.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {int action = (int) btn_cart.getTag (); if (action = ACTION_EDIT) {// showDelete ();} else if (action = ACTION_COMPLETE) {// change to edit status hideDelete ();}}});} /*** hide the delete button */private void hideDelete () {// 1. text settings-edit btn_cart.setText ("edit"); // 2. status settings edit btn_cart.setTag (ACTION_EDIT); // 3. the data settings are not all selected adapter. checkAll_none (true); adapter. checkAll (); // 4. hide button display, show settlement button btn_delete.setVisibility (View. GONE); btn_order.setVisibility (View. VISIBLE); // 5. price recalculates the adapter. showTotalPrice ();}/*** display the delete button */private void showDelete () {// 1. text settings-complete btn_cart.setText ("complete"); // 2. the status is set to btn_cart.setTag (ACTION_COMPLETE); // 3. the data settings are not all selected adapter. checkAll_none (false); adapter. checkAll (); // 4. the delete button is displayed, and the btn_delete.setVisibility (View. VISIBLE); btn_order.setVisibility (View. GONE); // 5. price recalculates the adapter. showTotalPrice ();}}

2 _ deleting the selected item from the adapter

In the GovaffairPager class

// Set click to delete btn_delete.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {// only deletes the selected adapter. deleteCart ();}});

 

Code in the adapter

/*** Delete selected data */public void deleteData () {// if (datas! = Null & datas. size ()> 0) {// for (int I = 0; I <datas. size (); I ++) {// ShoppingCart cart = datas. get (I); // if (cart. isCheck () {// 1. delete the local cache // cartProvider. deleteData (cart); // 2. delete the current memory // datas. remove (cart); // 3. refresh data // notifyItemRemoved (I); // I --; //} if (datas! = Null & datas. size ()> 0) {for (Iterator iterator = datas. iterator (); iterator. hasNext ();) {ShoppingCart cart = (ShoppingCart) iterator. next (); if (cart. isCheck () {// This line of code is put in front of int position = datas. indexOf (cart); // 1. delete the cartProvider of the local cache. deleteData (cart); // 2. delete the current memory // datas. remove (cart); iterator. remove (); // 3. refresh data policyitemremoved (position );}}}}

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.