-
Notifications
You must be signed in to change notification settings - Fork 78
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 #385 from linzihong888/master
- Loading branch information
Showing
10 changed files
with
298 additions
and
12 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...a/edu/hzuapps/androidlabs/homeworks/net1414080903131/Net1414080903131DetailActivity .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,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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ava/edu/hzuapps/androidlabs/homeworks/net1414080903131/Net1414080903131EditActivity .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,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(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ava/edu/hzuapps/androidlabs/homeworks/net1414080903131/Net1414080903131MainActivity .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,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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ava/edu/hzuapps/androidlabs/homeworks/net1414080903131/Net1414080903131MenuActivity .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 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); | ||
} | ||
}); | ||
|
||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...du/hzuapps/androidlabs/homeworks/net1414080903131/Net1414080903131MySQLiteOpenHelper.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,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) { | ||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...bs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903131/StudentBean .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,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; | ||
} | ||
} |
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
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
4 changes: 2 additions & 2 deletions
4
...layout/activity_net1414080903131_menu.xml → ...ayout/activity_net1414080903131_menu .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