· 7 years ago · Sep 12, 2018, 11:14 PM
1@Override
2protected void onStart() {
3 super.onStart();
4
5 mRef.addValueEventListener(new ValueEventListener() {
6 @Override
7 public void onDataChange(DataSnapshot dataSnapshot) {
8
9 pricesArrayList.clear();
10
11 for (DataSnapshot PricesListDataSnapshot : dataSnapshot.getChildren()) {
12
13 PricesList pricesList = PricesListDataSnapshot.getValue(PricesList.class);
14 pricesArrayList.add(pricesList);
15
16 // I don't know what is the insertion code to sqlite
17
18 }
19
20 // here is the retrieved data code of sqlite after saving it from firebase
21
22 }
23
24 @Override
25 public void onCancelled(DatabaseError databaseError) {
26
27 }
28 });
29}
30
31private class DBHelper extends SQLiteOpenHelper {
32 private static final int VERSION = 1;
33 private static final String DB_NAME = "MyDB1.db";
34 public static final String id = "_id";
35 public static final String ItemCode = "ItemCode";
36 public static final String Product = "Product";
37
38 DBHelper(Context context) {
39 super(context, DB_NAME, null, VERSION);
40 }
41
42 @Override
43 public void onCreate(SQLiteDatabase db) {
44 String create_sql = "CREATE TABLE IF NOT EXISTS "
45 + DB_NAME + '(' + id
46 + " INTEGER PRIMARY KEY AUTOINCREMENT,"
47 + ItemCode + " TEXT ,"
48 + Product + " TEXT ," +')';
49 db.execSQL(create_sql);
50
51 }
52
53 @Override
54 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
55 db.execSQL("DROP TABLE IF EXISTS " + DB_NAME );
56 }
57}