This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1153 from xyl123580/master
- Loading branch information
Showing
8 changed files
with
582 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package edu.hzuapps.androidlabs.Net1814080903110; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
public class MainSQLiteOpenHelper extends SQLiteOpenHelper { | ||
|
||
private static final String db_name = "MySchedule";//自定义的数据库名; | ||
private static final int version = 1;//版本号,增加则会执行onUpgrade方法? | ||
|
||
public MainSQLiteOpenHelper(Context context) { | ||
super(context, db_name, null, version); | ||
|
||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
String sql ="create table schedules(" + | ||
"id Integer primary key autoincrement," + //id自增,只支持integer不支持int | ||
"scheduleDetail varchar(50))"; | ||
db.execSQL(sql); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
db.execSQL("drop table if exists courses"); | ||
onCreate(db); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package edu.hzuapps.androidlabs.Net1814080903110; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Intent; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
public class Setting2Activity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private String schedule; | ||
private Button editBtn,deleteBtn; | ||
private EditText scheduleInput; | ||
private TestCourseData mySQLiteOpenHelper; | ||
private SQLiteDatabase myDatabase; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_setting_2); | ||
|
||
// 首先获取到意图对象 | ||
Intent intent = getIntent(); | ||
// 获取到传递过来的姓名 | ||
schedule = intent.getStringExtra("schedule"); | ||
|
||
initView(); | ||
} | ||
private void initView() { | ||
mySQLiteOpenHelper = new TestCourseData(this); | ||
myDatabase = mySQLiteOpenHelper.getWritableDatabase(); | ||
|
||
editBtn = findViewById(R.id.editBtn); | ||
editBtn.setOnClickListener(this); | ||
deleteBtn = findViewById(R.id.deleteSchedule); | ||
deleteBtn.setOnClickListener(this); | ||
scheduleInput = findViewById(R.id.scheduleInput); | ||
scheduleInput.setText(schedule); | ||
} | ||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()){ | ||
case R.id.deleteSchedule: | ||
deleteMySchedule(); | ||
break; | ||
case R.id.editBtn: | ||
editSchedule(); | ||
break; | ||
} | ||
} | ||
private void editSchedule() { | ||
ContentValues values = new ContentValues(); | ||
values.put("scheduleDetail",scheduleInput.getText().toString()); | ||
|
||
myDatabase.update("schedules",values,"scheduleDetail=?",new String[]{schedule}); | ||
|
||
Intent intent = new Intent(Setting2Activity.this, SettingActivity.class); | ||
startActivity(intent); | ||
} | ||
|
||
private void deleteMySchedule() { | ||
myDatabase.delete("schedules","scheduleDetail=?",new String[]{schedule}); | ||
|
||
Intent intent = new Intent(Setting2Activity.this, SettingActivity.class); | ||
startActivity(intent); | ||
} | ||
} |
Oops, something went wrong.