Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1153 from xyl123580/master
Browse files Browse the repository at this point in the history
#5 #26 第五次实验
  • Loading branch information
zengsn authored Nov 28, 2020
2 parents 7ad5d48 + f9c73dd commit a7f9d4b
Show file tree
Hide file tree
Showing 8 changed files with 582 additions and 73 deletions.
22 changes: 20 additions & 2 deletions students/net1814080903110/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="edu.hzuapps.androidlabs.Net1814080903110">

<application
Expand All @@ -9,8 +10,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".TestEditScheduleActivity"></activity>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:name=".RemindActivity"
android:label="Activity2">
<intent-filter>
<action android:name="com.intent.Activity2" />
Expand All @@ -19,7 +28,7 @@
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:name=".SettingActivity"
android:label="Activity1">
<intent-filter>
<action android:name="com.intent.Activity1" />
Expand All @@ -34,6 +43,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Setting2Activity"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
30 changes: 30 additions & 0 deletions students/net1814080903110/MainSQLiteOpenHelper.java
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);
}
}
60 changes: 26 additions & 34 deletions students/net1814080903110/Net1814080903110Activity.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
package edu.hzuapps.androidlabs.Net1814080903110;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.content.Intent;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;


public class Net1814080903110Activity extends AppCompatActivity {

private TestCourseData mySQLiteOpenHelper;
private String schedule;
private SQLiteDatabase myDatabase;
private Context context;
private TextView mySchedule[] = new TextView[5];


@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1814080903110);

//跳转按钮
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Net1814080903110Activity.this, SettingActivity.class);
startActivity(intent);
}
});
@Override
public void onClick(View v) {
Intent intent = new Intent(Net1814080903110Activity.this, SettingActivity.class);
startActivity(intent);
}
});
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -33,28 +46,7 @@ public void onClick(View v) {
startActivity(intent);
}
});

ListView lv = (ListView) findViewById(R.id.dates);

ArrayAdapter s1 = new ArrayAdapter<String>(this, R.layout.listview_item, mobileArray);

lv.setAdapter(s1);


AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

}
};
lv.setOnItemClickListener(listener);
}

String[] mobileArray = { //
"日程一", "日程二", "日程三", "日程四"
};

}
}}



71 changes: 71 additions & 0 deletions students/net1814080903110/Setting2Activity.java
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);
}
}
Loading

0 comments on commit a7f9d4b

Please sign in to comment.