· 6 years ago · Mar 15, 2019, 08:58 PM
1private final static String DBNAME = "Auction";
2private final static int DBVERSION = 2;
3
4SQLiteDatabase mDB5;
5
6public final static String TBL_AUCTION = "Auction";
7public final static String COL_AUCTION_ID = BaseColumns._ID;
8public final static String COL_AUCTION_NAME = "name";
9public final static String COL_AUCTION_DESCRIPTION = "description";
10public final static String COL_AUCTION_PRICE = "price";
11public final static String COL_AUCTION_DURATION = "duration";
12public final static String COL_AUCTION_IMAGE = "image";
13
14
15private String crt_tbl_auction = "CREATE TABLE IF NOT EXISTS " + TBL_AUCTION + "(" +
16 COL_AUCTION_ID + " INTEGER PRIMARY KEY, " +
17 COL_AUCTION_NAME + " TEXT, " +
18 COL_AUCTION_DESCRIPTION + " TEXT, " +
19 COL_AUCTION_PRICE + " TEXT, " +
20 COL_AUCTION_DURATION + " TEXT, " +
21 COL_AUCTION_IMAGE + " BLOB " +
22 ")";
23
24public DatabaseHelper5(Context context) {
25 super(context, DBNAME, null, DBVERSION);
26 mDB5 = this.getWritableDatabase();
27}
28
29public long insertData(String name, String description, String price, String duration,byte[] image) {
30 ContentValues cv = new ContentValues();
31 cv.put(COL_AUCTION_NAME, name);
32 cv.put(COL_AUCTION_DESCRIPTION, description);
33 cv.put(COL_AUCTION_PRICE, price);
34 cv.put(COL_AUCTION_DURATION, duration);
35 cv.put(COL_AUCTION_IMAGE,String.valueOf(image));
36
37 return mDB5.insert(TBL_AUCTION, null, cv);
38}
39
40public Cursor getDataV2() {
41
42 SQLiteDatabase db = this.getReadableDatabase();
43 String[] projection = {
44 COL_AUCTION_ID,
45 COL_AUCTION_IMAGE,
46 COL_AUCTION_NAME
47 };
48
49 return db.query(
50 TBL_AUCTION, // The table to query
51 projection, // The array of columns to return (pass null to get all)
52 null, null, null, null, BaseColumns._ID + " DESC"
53 );
54
55}
56
57gridView = (GridView)findViewById(R.id.gridView);
58 list = new ArrayList<>();
59 adapter = new AuctionAdapter(this,R.layout.auction_items,list);
60 gridView.setAdapter(adapter);
61 myDB5 = new DatabaseHelper5(this);
62
63
64 wholegrid = myDB5.getDataV2();
65 if (sma == null) {
66 sma = new SimpleCursorAdapter(
67 this,
68 android.R.layout.simple_list_item_2,wholegrid,
69 new String[]{DatabaseHelper5.COL_AUCTION_IMAGE, DatabaseHelper5.COL_AUCTION_NAME},
70 new int[]{android.R.id.text1,android.R.id.text2},
71 0
72 );
73 gridView.setAdapter(sma);
74 }
75 adapter.notifyDataSetChanged();
76
77}