· 7 years ago · Jan 05, 2019, 11:46 AM
1public class TravelDataUpdate extends AppCompatActivity {
2
3private static String DATABASE_TABLE = "tb_travel";
4private SQLiteDatabase db;
5private DBHelper dbHelper;
6
7private EditText photonameView2;
8private EditText albumnameView2;
9private EditText dataView2;
10private EditText placeView2;
11private EditText inforView2;
12Button btn;
13
14@Override
15protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.activity_travel_data_update);
18
19 dbHelper = new DBHelper(this);
20 db = dbHelper.getWritableDatabase();
21
22 photonameView2 = (EditText) findViewById(R.id.photo_name_update);
23 albumnameView2 = (EditText) findViewById(R.id.album_name_update);
24 dataView2 = (EditText) findViewById(R.id.photo_data_update);
25 placeView2 = (EditText) findViewById(R.id.photo_place_update);
26 inforView2 = (EditText) findViewById(R.id.photo_infor_update);
27 btn = (Button) findViewById(R.id.btn_update);
28
29 btn.setOnClickListener(new View.OnClickListener() {
30 @Override
31 public void onClick(View v) {
32 String photoname = photonameView2.getText().toString();
33 String albumname = albumnameView2.getText().toString();
34 String data = dataView2.getText().toString();
35 String place = placeView2.getText().toString();
36 String infor = inforView2.getText().toString();
37
38 ContentValues cv = new ContentValues();
39
40 cv.put("tbook", albumname);
41 cv.put("tdata", data);
42 cv.put("tplace", place);
43 cv.put("tnote", infor);
44
45 db.update(DATABASE_TABLE, cv, "tphoto='" + photoname + "'", new
46 String[]{"1"});
47
48 finish();
49 }
50 });
51}
52
53
54}
55
56public class DBHelper extends SQLiteOpenHelper {
57public static final int DATABASE_VERSION = 1;
58
59public DBHelper(Context context){
60 super(context, "traveldb", null, DATABASE_VERSION);
61}
62
63@Override
64public void onCreate(SQLiteDatabase db) {
65 String travlSql = "create table tb_travel (_id "+
66 "Integer primary key autoincrement, "+
67 "tphoto text not null, "+
68 "tbook, "+
69 "tdata, "+
70 "tplaese, "+
71 "tnote)";
72
73 String trailerSql = "create table tb_traveler (_id "+
74 "Integer primary key autoincrement, "+
75 "name not null, "+
76 "number, "+
77 "LineID, "+
78 "Gmail)";
79
80 db.execSQL(travlSql);
81 db.execSQL(trailerSql);
82}
83
84@Override
85public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
86 if (newVersion == DATABASE_VERSION){
87 db.execSQL("drop table if exists tb_travel");
88 db.execSQL("drip table if exists tb_traveler");
89 onCreate(db);
90 }
91}
92}