Eatwhatapp Development Combat (VI)

Source: Internet
Author: User

Last time, we added local storage to the app, but we found that the collection of stores that were stored when we exited the app disappeared, but the local records were just not read. Next, let's implement this feature.
    /*** Get Local data*/    Private voidGetlocaldata () {//Create or open a databasecreateoropendatabase (); //define a collection to store the names of the few stores we want.Shoplist =NewArraylist<shop>(); //cursors get items on a database formcursor cursor = db.query ("Shopinfo",NULL,NULL,NULL,NULL,NULL,NULL,NULL);  while(Cursor.movetonext ()) {//The first column is the name of the store that was previously definedString shopname = cursor.getstring (1); Shop Shop=NewShop (Shopname);        Shoplist.add (shop); }    }
This method is called at the beginning of Init () so that if the app has data locally, the data is displayed, and no new database and corresponding form is created. Next, add the delete function of the local data.
/** * Delete data * @param shop */private void Removelocaldata (Shop shop) {//Follow Shopname query and delete db.delete ("Shopinfo", "Shopname =?", New String[]{shop.getname ()});

To modify the confirmation key, click Listen:

Builder.setpositivebutton ("Confirm", new Dialoginterface.onclicklistener () {@Override public void OnClick (DIALOGINTERFAC      e dialog, int which) {//delete local data removelocaldata (Shoplist.get (position));      Removes the item shoplist.remove (position) in the collection;    Refresh shopadapter.notifydatasetchanged (); }  });
This allows the local read data and delete functions to be implemented.

Eatwhatapp Development Combat (VI)

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.