LitePal, the most convenient database in Android

Source: Internet
Author: User

LitePal, the most convenient database in Android

I recently saw the LitePal framework analyzed by Guo Shen. It feels very powerful and I tried it for a while. It is really good. I don't know if you are familiar with it. It varies from person to person. It feels very suitable for me.


After reading this, I thought about it. For me, the object has a set value assignment. If there is a lot of data, it will be too much trouble, what's more, my work is basically about interaction with the server, data, not to mention... generally, the data is transmitted in json format. Gson is used for parsing directly and no matter if it is thrown into the list. So I need to save the list content here. So, I downloaded the source code and looked at it, it's really powerful. I want all the content, and it's very convenient.


Nonsense said, first submitted the LItePal Source Code address: https://github.com/LitePalFramework/LitePal, to know his powerful look at the code will know, the source code provider is very kind, I can understand this English idiot, you must be able to understand it. You have finished speaking nonsense. Let's start talking about the little cainiao code!


1. Now download the LitePal source code. You can put the jar package in, or directly paste the source code. This can be arbitrary.

2. The newly created bean is named Student and barabara. You know what to do.

3. Let's take a look at my usage and go to the code.

Package com. sdufe. litepal; import java. util. arrayList; import java. util. list; import org. litepal. crud. dataSupport; import org. litepal. tablemanager. connector; import android. app. activity; import android. database. sqlite. SQLiteDatabase; import android. OS. bundle; import android. widget. textView; import com. sdufe. litepal. model. student;/*** @ author sub-ink ** 2014-10-30 */public class MainActivity extends Activity {private SQLiteDatabase db; private List
 
  
List; private Student student; private TextView mInformation; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); mInformation = (TextView) findViewById (R. id. student_information); // generate the student table db = Connector. getDatabase (); initDate (); // save DataSupport. saveAll (list); // find student = DataSupport. find (Student. class, 3); mInformation. setText ("name:" + student. getName () + "student ID:" + student. getNumber () + "Gender:" + student. getSex (); // update student = new Student (); student. setName ("vampire"); student. update (4); // Delete DataSupport. delete (Student. class, 4);}/*** Data assignment in the table */private void initDate () {list = new ArrayList
  
   
(); List. add (new Student (1, "20100854212", "zimo", "female"); list. add (new Student (2, "20100854211", "Thea", "female"); list. add (new Student (3, "20100854210", "Vampire", "female"); list. add (new Student (4, "20100854213", "klaus", "male"); list. add (new Student (5, "20100854213", "klaus", "male"); list. add (new Student (6, "20100854213", "klaus", "male"); list. add (new Student (7, "20100854213", "klaus", "male"); list. add (new Student (8, "20100854213", "klaus", "male"); list. add (new Student (9, "20100854213", "klaus", "male "));}}
  
 
They are very simple, mainly because the source code is too powerful and can be used directly. My list is saved mainly through saveall.


Hey, it's quite simple, but I can understand his source code and use it, and I feel that I have made some progress. I'm so happy that today I am here.


Address: http://download.csdn.net/detail/elinavampire/8101117

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.