Skip to content

Commit

Permalink
Merge pull request #385 from linzihong888/master
Browse files Browse the repository at this point in the history
#5 #154 第五次作业
  • Loading branch information
zengsn authored May 28, 2017
2 parents fd2f009 + 7c64478 commit 867f53f
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.studentinfo.R;

public class Net1414080903131DetailActivity extends AppCompatActivity {

TextView etName;
TextView etId;
TextView etClass;
TextView etDormitory;
TextView etSex;

Button btDelete;
Button btEdit;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903131_detail);
etName= (TextView) findViewById(R.id.tv_detail_name);
etClass= (TextView) findViewById(R.id.tv_detail_class);
etDormitory= (TextView) findViewById(R.id.tv_detail_dormitory);
etId= (TextView) findViewById(R.id.tv_detail_id);
etSex= (TextView) findViewById(R.id.tv_detail_sex);
StudentBean bean=get(getIntent().getStringExtra("id"));
if(bean!=null){
etSex.setText(bean.getSex());
etId.setText(bean.getId());
etDormitory.setText(bean.getDormitory());
etClass.setText(bean.getClazz());
etName.setText(bean.getName());
}

btDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Net1414080903131MySQLiteOpenHelper helper=new Net1414080903131MySQLiteOpenHelper(Net1414080903131DetailActivity.this);
SQLiteDatabase db=helper.getWritableDatabase();
db.delete("student","id=?",new String[]{getIntent().getStringExtra("id")});
db.close();
}
});
btEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Net1414080903131DetailActivity.this,Net1414080903131EditActivity.class));
}
});
}

public StudentBean get(String id){
StudentBean bean=null;
Net1414080903131MySQLiteOpenHelper helper=new Net1414080903131MySQLiteOpenHelper(this);
SQLiteDatabase db=helper.getReadableDatabase();
Cursor cursor=db.query("student",null,null,null,null,null,null);
while(cursor.moveToNext()){
if(cursor.getString(cursor.getColumnIndex("id")).equals(id)){
bean=new StudentBean();
bean.setName(cursor.getString(cursor.getColumnIndex("name")));
bean.setClazz(cursor.getString(cursor.getColumnIndex("clazz")));
bean.setDormitory(cursor.getString(cursor.getColumnIndex("dormitory")));
bean.setSex(cursor.getString(cursor.getColumnIndex("sex")));
}
}
cursor.close();
return bean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;

import com.example.administrator.studentinfo.R;

public class Net1414080903131EditActivity extends AppCompatActivity {

EditText etName;
EditText etId;
EditText etClass;
EditText etDormitory;
EditText etSex;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903131_edit);
etName= (EditText) findViewById(R.id.et_edit_name);
etClass= (EditText) findViewById(R.id.et_edit_class);
etDormitory= (EditText) findViewById(R.id.et_edit_dormitory);
etId= (EditText) findViewById(R.id.et_edit_id);
etSex= (EditText) findViewById(R.id.et_edit_sex);
}

public void save(StudentBean bean){
SQLiteOpenHelper helper=new Net1414080903131MySQLiteOpenHelper(this);
SQLiteDatabase db=helper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("name",bean.getName());
values.put("id",bean.getId());
values.put("clazz",bean.getClazz());
values.put("sex",bean.getSex());
values.put("dormitory",bean.getDormitory());
db.insert("student",null,values);
db.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.studentinfo.R;

public class Net1414080903131MainActivity extends AppCompatActivity {


Button btLogin;
Button btRegister;

EditText etUsername;
EditText etPassword;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903131_main);
btLogin= (Button) findViewById(R.id.bt_login);
btRegister= (Button) findViewById(R.id.bt_register);

etUsername= (EditText) findViewById(R.id.et_id);
etPassword= (EditText) findViewById(R.id.et_password);

String username=etUsername.getText().toString();
String password=etPassword.getText().toString();
if (check(username,password)){
startActivity(new Intent(Net1414080903131MainActivity.this,Net1414080903131MenuActivity.class));
}


}

public boolean check(String name,String password){
if (name.equals("linzihong")&&password.equals("123456")){
return true;
}return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.studentinfo.R;

public class Net1414080903131MenuActivity extends AppCompatActivity {

EditText etId;
Button btCheck;
Button btAdd;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903131_menu);
etId= (EditText) findViewById(R.id.et_search);
btAdd= (Button) findViewById(R.id.bt_add);
btCheck= (Button) findViewById(R.id.bt_check);
btCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Net1414080903131MenuActivity.this,Net1414080903131DetailActivity.class);
intent.putExtra("id",etId.getText().toString());
startActivity(intent);
}
});

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by Administrator on 2017/5/26.
*/

public class Net1414080903131MySQLiteOpenHelper extends SQLiteOpenHelper {
public Net1414080903131MySQLiteOpenHelper(Context context) {
super(context, "student", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table student(id varchar(20) primary key," +
"name varchar(20)," +
"sex varchar(20)," +
"clazz varchar(20)," +
"dormitory varchar(20));");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903131;

/**
* Created by Administrator on 2017/4/21.
*/

public class StudentBean {

String id;
String name;
String sex;
String dormitory;
String clazz;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getDormitory() {
return dormitory;
}

public void setDormitory(String dormitory) {
this.dormitory = dormitory;
}

public String getClazz() {
return clazz;
}

public void setClazz(String clazz) {
this.clazz = clazz;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">


<LinearLayout
android:layout_marginTop="10dp"
android:background="#ffffff"
android:padding="19dp"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand Down Expand Up @@ -97,7 +96,7 @@
android:id="@+id/textView2" />

<TextView
android:id="@+id/tv_detail_age"
android:id="@+id/tv_detail_dormitory"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?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">

<LinearLayout
android:layout_marginTop="9dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:padding="15dp"
android:layout_width="match_parent"
Expand Down Expand Up @@ -93,10 +93,10 @@
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="年龄: " />
android:text="宿舍: " />

<EditText
android:id="@+id/et_edit_age"
android:id="@+id/et_edit_dormitory"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,7 +9,7 @@
android:src="@drawable/stu_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="59dp"/>
android:layout_marginBottom="60dp"/>

<TextView
android:gravity="center_horizontal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="14dp"
android:padding="15dp"
android:orientation="horizontal">

<EditText
Expand Down

0 comments on commit 867f53f

Please sign in to comment.