一、团队成员信息
- 周泽加:学号:1600802138 班级:计算机164班 博客链接:https://www.cnblogs.com/ronzzj/
- 南加拉才让:学号:1600802093 班级:计算机163班 博客链接:https://www.cnblogs.com/nanjia/
- 李长栋:学号:1600802085 班级:计算机163班 博客链接:https://www.cnblogs.com/L0HEYNI/
二、APK链接:https://raw.githubusercontent.com/ronzzj/Android-Named/master/MyApplication/app-debug.apk
三、代码链接:https://github.com/ronzzj/Android-Named.git
四、团队项目
4.1 团队项目的总体效果截图
4.2 实现的功能及其效果的描述
功能:1.上课顺序点名功能
2.上课 随机点名功能
3.查询信息功能
4.修改学生信息功能
5.显示公告
效果:能够从数据库中找出学生信息进行顺序、随机点名,并可以修改数据库中的学生信息。
项目效果录屏:
五、给出项目中的关键代码
5.1 学生数据操作:
package com.example.administrator.myapplication; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class addActivtiy extends AppCompatActivity { static TextView info; static EditText mEditText01; static EditText mEditText02; static EditText mEditText03; static EditText mEditText04; Cursor cursor; Button exBtn; Button createBtn, openBtn, upBtn, downBtn; Button addBtn, updateBtn, deleteBtn; SQLiteDatabase db; DBConnection helper; public int id_this; Bundle savedInstanceState; static String TABLE_NAME = "Student"; static String ID = "_id"; static String NAME = "name"; static String NUMBER = "number"; static String ABSENT = "absent"; static String LATE = "late"; Toast toast; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); mEditText01 = (EditText)findViewById(R.id.EditText01); mEditText02 = (EditText)findViewById(R.id.EditText02); mEditText03 = (EditText)findViewById(R.id.EditText03); mEditText04 = (EditText)findViewById(R.id.EditText04); upBtn=(Button)findViewById(R.id.up1); upBtn.setOnClickListener(new ClickEvent()); downBtn=(Button)findViewById(R.id.down1); downBtn.setOnClickListener(new ClickEvent()); addBtn = (Button)findViewById(R.id.add1); addBtn.setOnClickListener(new ClickEvent()); updateBtn = (Button)findViewById(R.id.update1); updateBtn.setOnClickListener(new ClickEvent()); deleteBtn = (Button)findViewById(R.id.delete1); deleteBtn.setOnClickListener(new ClickEvent()); exBtn = (Button)findViewById(R.id.exBtn); exBtn.setOnClickListener(new ClickEvent()); try { db = openOrCreateDatabase("Students.db", Context.MODE_PRIVATE, null); cursor = db.query("Student", null, null, null, null, null, null); if (cursor.getCount()>0) { cursor.moveToNext(); datashow(); } else { upBtn.setEnabled(false); downBtn.setEnabled(false); updateBtn.setEnabled(false); deleteBtn.setEnabled(false); info.setText("数据库为空,先添加学生信息"); } }catch(Exception e){ helper = new DBConnection(addActivtiy.this); SQLiteDatabase db = helper.getWritableDatabase(); // createData(); } } class ClickEvent implements OnClickListener { public void onClick(View v) { switch(v.getId()) { case R.id.exBtn: exAdd(); cursor = db.query("Student", null, null, null, null, null, null); cursor.moveToNext(); datashow(); break; case R.id.up1: if(!cursor.isFirst()) cursor.moveToPrevious(); datashow(); break; case R.id.down1: if(!cursor.isLast()) cursor.moveToNext(); datashow(); break; // case R.id.add1: add(); cursor = db.query("Student", null, null, null, null, null, null); try{ if (cursor.getCount()>0){ cursor.moveToNext(); datashow(); } else{ upBtn.setEnabled(false); downBtn.setEnabled(false); updateBtn.setEnabled(false); deleteBtn.setEnabled(false); } }catch (Exception e){ } break; case R.id.update1: update(); cursor = db.query("Student", null, null, null, null, null, null); cursor.moveToNext(); datashow(); showToast("数据更新成功!"); break; case R.id.delete1: delete(); cursor = db.query("Student", null, null, null, null, null, null); try{ if (cursor.getCount()>0){ cursor.moveToNext(); datashow(); } else{ mEditText01.setText(""); mEditText02.setText(""); upBtn.setEnabled(false); downBtn.setEnabled(false); updateBtn.setEnabled(false); deleteBtn.setEnabled(false); info.setText("数据库为空,请添加学生信息"); } }catch (Exception e){ } showToast("数据删除成功!"); break; } } } void datashow() { if (cursor.getCount()>0) { id_this = Integer.parseInt(cursor.getString(0)); String name_this = cursor.getString(1); String number_this = cursor.getString(2); String absent_this = cursor.getString(3); String late_this = cursor.getString(4); mEditText01.setText(name_this); mEditText02.setText(number_this); mEditText03.setText(absent_this); mEditText04.setText(late_this); } else{ upBtn.setEnabled(false); downBtn.setEnabled(false); updateBtn.setEnabled(false); deleteBtn.setEnabled(false); info.setText("数据库为空,先添加学生信息"); } } void add() { if(mEditText01.getText().toString().length()>0&&mEditText02.getText().toString().length()>0){ try{ db = openOrCreateDatabase("Students.db", Context.MODE_PRIVATE, null) ; ContentValues values1 = new ContentValues(); values1.put(NAME, addActivtiy.mEditText01.getText().toString()); values1.put(NUMBER, addActivtiy.mEditText02.getText().toString()); values1.put(ABSENT, addActivtiy.mEditText03.getText().toString()); values1.put(LATE, addActivtiy.mEditText04.getText().toString()); db.insert(TABLE_NAME, null, values1); showToast("数据添加成功!"); upBtn.setEnabled(true); downBtn.setEnabled(true); updateBtn.setEnabled(true); deleteBtn.setEnabled(true); } catch (Exception e){ } } else {showToast("名字或学号不能为空!"); } } void update() { try { ContentValues values = new ContentValues(); values.put(NAME, addActivtiy.mEditText01.getText().toString()); values.put(NUMBER, addActivtiy.mEditText02.getText().toString()); values.put(ABSENT, addActivtiy.mEditText03.getText().toString()); values.put(LATE, addActivtiy.mEditText04.getText().toString()); String where1 = ID + " = " + id_this; db.update(TABLE_NAME, values, where1, null); db = helper.getWritableDatabase(); } catch (Exception e){ } } void delete() { try{ String where = ID + " = " + id_this; db.delete(TABLE_NAME, where ,null); db = helper.getWritableDatabase(); } catch (Exception e){ } } void showToast(String str){ toast = Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER,0,0); toast.show(); } void createData(){ String TABLE_NAME = "Student"; String ID = "_id"; String NAME = "name"; String NUMBER = "number"; String ABSENT = "absent"; String LATE = "late"; SQLiteDatabase db; String db_name = "Students.db"; String sqlStr = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER primary key autoincrement, " + NAME + " text not null, " + NUMBER + " text not null, " + ABSENT + " text not null, " + LATE + " text not null "+ ");"; int mode = Context.MODE_PRIVATE; db = this.openOrCreateDatabase(db_name,mode,null); db.execSQL(sqlStr); } }
5.2 查询学生信息
package com.example.administrator.myapplication; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DBConnection extends SQLiteOpenHelper { static final String Database_name = "Students.db"; static final int Database_Version = 1; SQLiteDatabase db; public int id_this; Cursor cursor; static String TABLE_NAME = "Student"; static String ID = "_id"; static String NAME = "name"; static String NUMBER = "number"; static String ABSENT = "absent"; static String LATE = "late"; DBConnection(Context ctx) { super(ctx, Database_name, null, Database_Version); } public void onCreate(SQLiteDatabase database) { String sql = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER primary key autoincrement, " + NAME + " text not null, " + NUMBER + " text not null, " + ABSENT + " text not null, " + LATE + " text not null "+ ");"; database.execSQL(sql); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
5.3 MainActivity:
package com.example.administrator.myapplication; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class MainActivity extends AppCompatActivity { ImageButton addBtn; ImageButton turnBtn; ImageButton ranBtn; ImageButton webBtn; ImageButton selectBtn; ImageButton outBtn; DBConnection helper; Toast toast; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); addBtn = (ImageButton)findViewById(R.id.addBtn); addBtn.setOnClickListener(new addClick()); turnBtn = (ImageButton)findViewById(R.id.turnBtn); turnBtn.setOnClickListener(new turnClick()); ranBtn = (ImageButton)findViewById(R.id.ranBtn); ranBtn.setOnClickListener(new ranClick()); webBtn = (ImageButton)findViewById(R.id.noBtn); webBtn.setOnClickListener(new webClick()); selectBtn = (ImageButton)findViewById(R.id.selectBtn); selectBtn.setOnClickListener(new selectClick()); outBtn = (ImageButton)findViewById(R.id.outBtn); outBtn.setOnClickListener(new outClick()); } class addClick implements View.OnClickListener{ public void onClick(View v){ Intent intent = new Intent(MainActivity.this, addActivtiy.class); startActivity(intent); } } class turnClick implements View.OnClickListener{ public void onClick(View v){ Intent intent = new Intent(MainActivity.this, turnActivity.class); startActivity(intent); } } class ranClick implements View.OnClickListener{ public void onClick(View v){ Intent intent = new Intent(MainActivity.this, randomActivity.class); startActivity(intent); } } class webClick implements View.OnClickListener{ public void onClick(View v){ Intent intent = new Intent(MainActivity.this,webActivity.class); startActivity(intent); } } class selectClick implements View.OnClickListener{ public void onClick(View v){ Intent intent = new Intent(MainActivity.this, selectActivity.class); startActivity(intent); } } class outClick implements View.OnClickListener{ public void onClick(View v){ System.exit(0); } } }
5.4 查询结果:
package com.example.administrator.myapplication; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class numberActivity extends AppCompatActivity { static TextView TextView1; static TextView TextView2; static TextView TextView3; static TextView TextView4; TextView info; SQLiteDatabase db; Cursor cursor; DBConnection helper; public int id_this; Bundle savedInstanceState; static String TABLE_NAME = "Student"; static String ID = "_id"; static String NAME = "name"; static String NUMBER = "number"; static String ABSENT = "absent"; static String LATE = "late"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_number); TextView1 = (TextView)findViewById(R.id.TextView1); TextView2 = (TextView)findViewById(R.id.TextView2); TextView3 = (TextView)findViewById(R.id.TextView3); TextView4 = (TextView)findViewById(R.id.TextView4); info = (TextView)findViewById(R.id.info); Intent intent = getIntent(); String number = intent.getStringExtra("number"); db = openOrCreateDatabase("Students.db", Context.MODE_PRIVATE, null) ; cursor = db.query("Student", null , null, null, null, null, null); int flag = 0; while(!cursor.isLast()){ cursor.moveToNext(); String stuNumber = cursor.getString(2); if (stuNumber.equals(number)) { flag = 1; break; } } if(flag == 0) info.setText("没有找到学号为 "+number+" 的学生"); datashow(); } void datashow() { id_this = Integer.parseInt(cursor.getString(0)); String name_this = cursor.getString(1); String number_this = cursor.getString(2); String absent_this = cursor.getString(3); String late_this = cursor.getString(4); TextView1.setText(name_this); TextView2.setText(number_this); TextView3.setText(absent_this); TextView4.setText(late_this); } }
5.5 添加数据库:
package com.example.administrator.myapplication; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class random2Activity extends AppCompatActivity { Button absentBtn,lateBtn,skipBtn; TextView TextView1,TextView2,TextView3,TextView4,info; Cursor cursor; SQLiteDatabase db; DBConnection helper; public int id_this; Bundle savedInstanceState; static String TABLE_NAME = "Student"; static String ID = "_id"; static String NAME = "name"; static String NUMBER = "number"; static String ABSENT = "absent"; static String LATE = "late"; Toast toast; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_random2); TextView1=(TextView)findViewById(R.id.TextView1); TextView2=(TextView)findViewById(R.id.TextView2); TextView3=(TextView)findViewById(R.id.TextView3); TextView4=(TextView)findViewById(R.id.TextView4); info=(TextView)findViewById(R.id.info); absentBtn = (Button)findViewById(R.id.absentBtn); absentBtn.setOnClickListener(new mClick()); lateBtn = (Button)findViewById(R.id.lateBtn); lateBtn.setOnClickListener(new mClick()); skipBtn = (Button)findViewById(R.id.skipBtn); skipBtn.setOnClickListener(new mClick()); try { db = openOrCreateDatabase("Students.db", android.content.Context.MODE_PRIVATE, null); cursor = db.query("Student", null, null, null, null, null, null); int i = (int) (Math.random() * cursor.getCount()); cursor.moveToPosition(i); datashow(); }catch (Exception e){ absentBtn.setEnabled(false); lateBtn.setEnabled(false); skipBtn.setEnabled(false); showToast("数据库为空,请先添加学生信息!"); } } class mClick implements View.OnClickListener { public void onClick(View v){ switch(v.getId()) { case R.id.absentBtn:{ absent(); Intent intent = new Intent(random2Activity.this,randomActivity.class); startActivity(intent); random2Activity.this.finish(); showToast("操作成功!"); break; } case R.id.lateBtn:{ late(); Intent intent = new Intent(random2Activity.this,randomActivity.class); startActivity(intent); random2Activity.this.finish(); showToast("操作成功!"); break; } case R.id.skipBtn:{ Intent intent = new Intent(random2Activity.this,randomActivity.class); startActivity(intent); random2Activity.this.finish(); showToast("操作成功!"); break; // } } } } void absent(){ try { int absent = Integer.parseInt(TextView3.getText().toString()) + 1; android.content.ContentValues values = new android.content.ContentValues(); values.put(NAME, TextView1.getText().toString()); values.put(NUMBER, TextView2.getText().toString()); values.put(ABSENT, absent+""); values.put(LATE, TextView4.getText().toString()); String where1 = ID + " = " + id_this; db.update(TABLE_NAME, values, where1, null); db = helper.getWritableDatabase(); db.close(); } catch (Exception e){} } void late(){ try { int late = Integer.parseInt(TextView4.getText().toString()) + 1; android.content.ContentValues values = new android.content.ContentValues(); values.put(NAME, TextView1.getText().toString()); values.put(NUMBER, TextView2.getText().toString()); values.put(ABSENT, TextView3.getText().toString()); values.put(LATE, late+""); String where1 = ID + " = " + id_this; db.update(TABLE_NAME, values, where1, null); db = helper.getWritableDatabase(); db.close(); } catch (Exception e){} } void datashow() { id_this = Integer.parseInt(cursor.getString(0)); String name_this = cursor.getString(1); String number_this = cursor.getString(2); String absent_this = cursor.getString(3); String late_this = cursor.getString(4); TextView1.setText(name_this); TextView2.setText(number_this); TextView3.setText(absent_this); TextView4.setText(late_this); } void showToast(String str){ toast = Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER,0,0); toast.show(); } }
六、心目中前五的的apk
1.盖星辰组:该组做的是一个游戏app,实现的功能有1.小人左右移动。2、自动生成挡板3、检测失败条件。4、实现难度控制5、记录得分并实现排行榜。6、播放音乐。7、流畅播放小人下落的动画。我们全体小组都认为改组做的比较好。
2.孟凡锚组:该组做的是一个音乐播放器app,实现的功能有在一开始的开始页面实现欢迎页面视频的播放,感觉效果和创意非常好,再还有海报的滑动播放功能也不错。最后认为比较好的是列表的展示,点击播放并改变颜色换等。
3.沈顺文组:该组做的是一个游戏app,改组的登录注册都能实现,并且游戏体验感比较好。
4.张琦组:该项目主要实现的信息的查询功能,查询一些课程的信息,而且也可以发布信息,界面比较简洁。
5.李钊组:该组的首页顶部使用轮播图展示了一些球员的照片,下面紧接着的是当下的时事新闻,点击相应的新闻可以查看具体内容,比较简洁。第二页展示了最新的球员世界排名。第三页是部分球员的详细介绍。第四页列出了2019年乒乓球的赛事赛程。第五页是精彩集锦,点击可以查看相关的视频。
七、团队成员做项目中遇到的问题,以及解决方法
李长栋:1.在实现随机点名功能时会出现打开学生数据表时一直会报错的情况。
2.可以添加空记录的异常错误。
南加拉才让:1.删除最后一个数据时不可避免的异常
2.无法添加数据库
周泽加:1.运行程序时,出现闪退情况;R包丢失
2.运行项目时出现错误:Information:Gradle tasks,
八、说明团队成员在本次项目中的分工、占了总工作的多少?以及对项目成员打分
姓名 | 分工 | 工作比例 | 分数 |
李长栋 | 顺序点名模块 | 25% | 10 |
南加拉才让 | 随机点名模块 | 25% | 10 |
周泽加 | 查询信息模块 | 25% | 10 |
苏毅俊 | 修改学生信息模块 | 25% | 10 |