Recently saw the Guo Shen analysis of the Litepal framework, feel very strong, try it, really good, you are not accustomed to I do not know, vary, it feels very suitable for me
After reading, think about, for me, the entity to a set assignment, if the data a lot of that can be troublesome, not to mention I am now working content is basically interacting with the server, data, needless to say ... Generally is JSON transfer data, directly with Gson parsing, throw to list inside no matter, so I need to put the list content to save, so, I downloaded the source code, looked, really very powerful, I want the content has, and also very convenient
Less nonsense, first presented Litepal source address: Https://github.com/LitePalFramework/LitePal, want to know his strong see code to know, source provider is very kind, I this kind of English idiot can read, You must be able to understand, the nonsense is finished, start talking about the code of small rookie!
1. Now download Litepal source code, you can put the jar in the package, you can also directly paste the source, this can be arbitrary
2. New bean named student, Balabala, you know what to do.
3. To see how I use it, on 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 SQLi Tedatabase db;private list<student> 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 student Table db = Connector.getdatabase (); initdate ();//Save Datasupport.saveall (list);//Find Student = Datasupport.find (Student.class, 3) ; Minformation.settext ("Name:" + student.getname () + "study Number:" + student.getnumber () + "Gender:" + student.getsex ());//Update student= New Student (); Student.setname ("Vampire"); StUdent.update (4);//delete Datasupport.delete (Student.class, 4);} /** * Table data assignment */private void Initdate () {list = new arraylist<student> (); List.add (New Student (1, "20100854212", "sub-ink", "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"));}}are very simple, the main source is too powerful, directly grabbed to use it, my list is mainly saved through the SaveAll implementation
Hey, very simple, but can read his source code, and then use, and feel that their progress a little, a little happy, today to this
Code Address: http://download.csdn.net/detail/elinavampire/8101117
The most convenient database in Android--litepal