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 );}}}}