-
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 #815 from liwenjie0/master
#92#27实验6
- Loading branch information
Showing
8 changed files
with
204 additions
and
9 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
.../edu/hzuapps/androidworks/homeworks/com1314080901221/Com1314080901221Activity_Insert.java
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,52 @@ | ||
package com.example.lwj_pc.my_classwork; | ||
|
||
import android.app.Activity; | ||
import android.content.ContentValues; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
/** | ||
* Created by LWJ-PC on 2016/5/10. | ||
*/ | ||
public class Com1314080901221Activity_Insert extends Activity { | ||
private EditText title,content; | ||
private Button tijiao; | ||
private Com1314080901221_MyDBHelper dbHelper; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_com1314080901221_insert); | ||
|
||
dbHelper=new Com1314080901221_MyDBHelper(this,"Myapp.db",null,1); //获取数据库实例 | ||
|
||
title=(EditText)findViewById(R.id.insert_title); | ||
content=(EditText)findViewById(R.id.insert_context); | ||
tijiao=(Button)findViewById(R.id.insert_tijiao); | ||
tijiao.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String message_title = title.getText().toString(); | ||
String message_content = content.getText().toString(); | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd;HH:mm:ss"); | ||
Date date=new Date(); | ||
String datetime = dateFormat.format(date); | ||
Toast.makeText(Com1314080901221Activity_Insert.this, datetime, Toast.LENGTH_SHORT).show(); | ||
|
||
SQLiteDatabase db=dbHelper.getWritableDatabase(); | ||
ContentValues values=new ContentValues(); | ||
values.put("title",message_title); | ||
values.put("content",message_content); | ||
values.put("time",datetime); | ||
db.insert("journey",null,values); | ||
} | ||
}); | ||
|
||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...java/edu/hzuapps/androidworks/homeworks/com1314080901221/Com1314080901221_MyDBHelper.java
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,35 @@ | ||
package com.example.lwj_pc.my_classwork; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Created by LWJ-PC on 2016/5/10. | ||
*/ | ||
public class Com1314080901221_MyDBHelper extends SQLiteOpenHelper { | ||
//定义一个Context变量,用于保存活动调用本参数时传入的Context,并方便本类的其他方法使用。 | ||
private Context mycontext; | ||
//此处书写数据库建表语句 | ||
public static final String CREATE_TABLE="create table journey (" | ||
+"title text," | ||
+"content text," | ||
+"time text)"; | ||
//构造函数 | ||
public Com1314080901221_MyDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { | ||
super(context, name, factory, version); | ||
mycontext=context; | ||
} | ||
//创建时执行,当检查到数据库不存在时,执行onCreate进行创建。 | ||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL(CREATE_TABLE); | ||
Toast.makeText(mycontext, "建表成功", Toast.LENGTH_SHORT).show(); | ||
} | ||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
|
||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/res/layout/activity_com1314080901221_insert.xml
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,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:text="添加记录" | ||
android:textSize="25dp" | ||
android:background="#FFF5EE" | ||
android:gravity="center" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
<LinearLayout | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="#22aabb"> | ||
<TextView | ||
android:text="标题:" | ||
android:gravity="center" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" /> | ||
<EditText | ||
android:id="@+id/insert_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:maxLength="30" | ||
android:hint="30字内" | ||
/> | ||
</LinearLayout> | ||
|
||
<EditText | ||
android:id="@+id/insert_context" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="20sp" | ||
android:maxLength="200" | ||
android:hint="200字内" /> | ||
|
||
|
||
<Button | ||
android:id="@+id/insert_tijiao" | ||
android:text="提交" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> |
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
12 changes: 12 additions & 0 deletions
12
app/src/main/res/layout/activity_com1314080901221_main_0.xml
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@drawable/com13140809012221pic1"> | ||
<ListView | ||
android:id="@+id/list_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
</ListView> | ||
|
||
</LinearLayout> |
15 changes: 15 additions & 0 deletions
15
app/src/main/res/layout/activity_com1314080901221_mian_drawer.xml
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="230dp" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="start" | ||
android:background="#fff"> | ||
|
||
<TextView | ||
android:text="这是抽屉" | ||
android:textSize="30sp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
</LinearLayout> |
11 changes: 11 additions & 0 deletions
11
app/src/main/res/layout/activity_com1314080901221_toolbar.xml
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.Toolbar | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/mytoolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@color/colorAccent" | ||
android:minHeight="?attr/actionBarSize" | ||
android:theme="@style/Theme.Drawer.ArrowAnimation"> | ||
|
||
</android.support.v7.widget.Toolbar> |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context=".Com1314080901221Activity"> | ||
<item | ||
android:id="@+id/action_insert" | ||
android:title="添加" | ||
android:orderInCategory="90" | ||
app:showAsAction="always"/> | ||
<item | ||
android:id="@+id/action_more" | ||
android:title="More" | ||
android:orderInCategory="100" | ||
app:showAsAction="never"/> | ||
<item | ||
android:id="@+id/action_settings" | ||
android:orderInCategory="100" | ||
android:title="设置" | ||
app:showAsAction="never" /> | ||
</menu> |