Skip to content

Commit

Permalink
Merge pull request #815 from liwenjie0/master
Browse files Browse the repository at this point in the history
#92#27实验6
  • Loading branch information
zengsn committed May 24, 2016
2 parents a3965ed + 7932253 commit b1899f5
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 9 deletions.
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);
}
});

}
}

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 app/src/main/res/layout/activity_com1314080901221_insert.xml
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>
20 changes: 11 additions & 9 deletions app/src/main/res/layout/activity_com1314080901221_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/list_view"
<!-- Toolbar -->
<include layout="@layout/activity_com1314080901221_toolbar"/>
<!-- Drawer组件 -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/main_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/com13140809012221pic1"/>
android:layout_height="match_parent">
<!-- 主页面视图 -->
<include layout="@layout/activity_com1314080901221_main_0"/>
<!-- 抽屉视图 -->
<include layout="@layout/activity_com1314080901221_mian_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_com1314080901221_main_0.xml
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 app/src/main/res/layout/activity_com1314080901221_mian_drawer.xml
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 app/src/main/res/layout/activity_com1314080901221_toolbar.xml
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>
21 changes: 21 additions & 0 deletions app/src/main/res/menu/com1314080901221_main.xml
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>

0 comments on commit b1899f5

Please sign in to comment.