1、完整版Android学生信息管理系统APPAndroid 学生信息管理系统 APP一、需求剖析为了方便的进行对学生数据库的操作, 本 app 可在 android 设施长进行对学生信息数据库的信息管理功能,详细功能以下:1.对数据库中全部学生姓名进行显示, 对各个条目进行点击可睁开具体信息2.查问数据:查问数据是依据姓名与学号两个条件进行查问,二者满足任一条件则进行模糊查问, 两个条件同时知足则进行精准查问, 查询结果界面与功能一中相同,以姓名摆列,点击睁开全部信息3.增加数据:在数据库中增加条目,包含姓名(字符串),学号(数字,主键),性别(单项选择框),年纪(数字),专业(字符串)。每个条
2、目均有误输入设定, 且主键可检查重复性, 全部数据可检查完好性,若插入成功则会显示一条信息提示成功, 若失败则会提示检查主键重复或许数据不完好4.改正数据:依据姓名学号进行精准查找, 查找成功后转入改正界面,为了防备漏填与便利改正界面会默认填补以前的数据(除学号),修改完成即可更新,相同会检查数据完好性15.删除数据:依据姓名学号进行精准查找,查找成功则会进行删除,并显示一条删除成功的提示,若失败,也会进行提示二、观点构造设计ER 图:三、逻辑构造设计学生:姓名(字符串)学号(数字,主码)2性别(单项选择框)年纪(数字)专业(字符串)create table student(name TEXT
3、,NO TEXT Primary Key,sex TEXT,profession TEXT,age TEXT)四、详细实现1.主界面:3主界面显示全部功能,每个按钮点击后,跳转进入相应功能中心代码:public class Main extends Activity SQLiteDatabase db ;Button btn_search ;Button btn_modify ;Button btn_add ;Button btn_delete ;Button btn_quit ;Button btn_show ;Overrideprotected void onCreate(Bundle s
4、avedInstanceState) requestWindowFeature(Window. FEATURE_NO_TITLE );getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN );super .onCreate(savedInstanceState);setContentView(R.layout. layout_main );/翻开数据库,若不存在,则创立db =SQLiteDatabase.openOrCreate
5、Database( this.getFilesDir().toString()+/Student.db3, null);btn_search= (Button) findViewById(R.id.btn_search);btn_modify= (Button) findViewById(R.id.btn_modify);btn_add= (Button) findViewById(R.id.btn_add );btn_delete= (Button) findViewById(R.id.btn_delete);btn_quit= (Button) findViewById(R.id.btn_
6、quit);btn_show=(Button) findViewById(R.id.Btn_show);tryCursor cursor = db .rawQuery( select * from student , null );cursor.close();catch (SQLiteException e)4db .execSQL( create table student+(+name TEXT,+NO TEXT Primary Key,+sex TEXT,+profession TEXT,+age TEXT+) );/显示全部数据按钮的功能实现btn_show .setOnClickL
7、istener( new OnClickListener()public void onClick(View source) /获得指针Cursor cursor = db .rawQuery( select * from student , null );/ 判断数据库能否不存在任何数据if (cursor.moveToFirst() = false )Toast. makeText (Main. this , 不存在记录 ,Toast. LENGTH_SHORT ).show();elseList p = new ArrayList();List re_name = new ArrayLi
8、st();List info = new ArrayList();/保留搜寻出的全部数据for (cursor.moveToFirst() ; !cursor.isAfterLast() ;cursor.moveToNext()intnameColume = cursor.getColumnIndex(name );intNOColume = cursor.getColumnIndex(NO );intproColume =cursor.getColumnIndex(profession);intsexColume = cursor.getColumnIndex(sex);intageColu
9、me = cursor.getColumnIndex(age);Student student =new Student();student.name= 姓名: +cursor.getString(nameColume);student.NO =学号:+cursor.getString(NOColume);student.sex = 性别 :+cursor.getString(sexColume);5student. profession = 专业: +cursor.getString(proColume);student. age = 年纪 : +cursor.getString(ageCo
10、lume);p.add(student);String temp = student.MakeString();info.add(temp);String newname = cursor.getString(nameColume);re_name.add(newname);/对保留的数据进行封装String Cur_name = new Stringre_name.size();Cur_name = re_name.toArray(Cur_name);String Cur_info = new Stringinfo.size();Cur_info = info.toArray(Cur_inf
11、o);Bundle bundle = new Bundle();bundle.putStringArray( name , Cur_name);Student data = new Student();data. info = Cur_info;/ 将封装的数据传达给结果界面的 activityIntent intent = newIntent(Main. this ,SearchResult. class );intent.putExtras(bundle);intent.putExtra( data , data);startActivity(intent);cursor.close();
12、);/为剩下的按钮绑定监听器实现跳转功能btn_search .setOnClickListener( new OnClickListener()public void onClick(View source) Intent intent = new Intent(Main. this ,Search. class );startActivity(intent););6btn_modify .setOnClickListener( new OnClickListener()public void onClick(View source) Intent intent = new Intent(M
13、ain. this ,Modify. class );startActivity(intent););btn_add .setOnClickListener( new OnClickListener()public void onClick(View source) Intent intent = new Intent(Main. this ,Add. class );startActivity(intent););btn_delete .setOnClickListener( new OnClickListener()public void onClick(View source) Inte
14、nt intent = new Intent(Main. this ,Delete. class );startActivity(intent););btn_quit .setOnClickListener( new OnClickListener()public void onClick(View source) db .close();finish(););2.数据显示界面:7按姓名摆列,点击条目睁开详细信息中心代码:public class SearchResult extends ActivitySuppressLint ( RtlHardcoded )public void onCr
15、eate(Bundle savedInstanceState)requestWindowFeature(Window. FEATURE_NO_TITLE );getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN );/获得传递来的数据super .onCreate(savedInstanceState);setContentView(R.layout. layout_result );final Intent intent = g
16、etIntent();BaseExpandableListAdapter adapter = newBaseExpandableListAdapter()8/提取数据Bundle bundle = intent.getExtras();Student mem_data = (Student)getIntent().getExtras().get( data );String people = (String) bundle .getSerializable( name );String data = mem_data . info ;public Object getChild( int gr
17、oupPosition, int childPosition)return data groupPositionchildPosition;public long getChildId( int groupPosition, int childPosition)return childPosition;public int getChildrenCount( int groupPosition)return data groupPosition. length ;/设定每个子选项每行的显示方式private TextView getTextView()AbsListView.LayoutPar
18、ams lp = newAbsListView.LayoutParams(ViewGroup.LayoutParams. MATCH_PARENT,ViewGroup.LayoutParams. MATCH_PARENT);TextView textView = new TextView(SearchResult. this );textView.setLayoutParams(lp);textView.setGravity(Gravity. CENTER_VERTICAL |Gravity. LEFT );textView.setPadding(36, 0, 0, 0);textView.s
19、etTextSize(20);return textView;/设定每个子选项显示内容public View getChildView( int groupPosition , intchildPosition, boolean isLastChild,View convertView,ViewGroup Parent)TextView textView = getTextView();textView.setText( +getChild(groupPosition,childPosition).toString(); return textView;9public Object getGr
20、oup( int groupPosition)return people groupPosition;public int getGroupCount()return people . length ;public long getGroupId( int groupPosition)return groupPosition;/设定每个组选项显示内容public View getGroupView( int groupPosition, booleanisExpanded ,View convertView , ViewGroup parnet)LinearLayout ll = new Li
21、nearLayout(SearchResult. this );ll.setOrientation(0);TextView textView = getTextView();textView.setText( +getGroup(groupPosition).toString(); ll.addView(textView);return ll;ExpandableListView expandListView = (ExpandableListView)findViewById(R.id. list );expandListView.setAdapter(adapter);103.增加数据界面
22、:依据文本框输入内容进行数据的插入, 且拥有完好性和重复性的判断, 插入成功失败均会产生提示中心代码:public class Add extends Activity SQLiteDatabase db ;Button btn_Accept ;Button btn_Cancle ;TextView ET_name ;TextView ET_NO ;TextView ET_Pro ;TextView ET_Age ;11RadioGroup rg ;String radio_sex = 男 ;Overrideprotected void onCreate(Bundle savedInstanc
23、eState) requestWindowFeature(Window. FEATURE_NO_TITLE );getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN );super .onCreate(savedInstanceState);setContentView(R.layout. layout_add );db =SQLiteDatabase. openDatabase ( this .getFilesDir().toS
24、tring()+ b3 , null ,SQLiteDatabase. OPEN_READWRITE );btn_Accept = (Button) findViewById(R.id. btn_Accept );btn_Cancle = (Button) findViewById(R.id. btn_Cancle );ET_name = (TextView) findViewById(R.id. ET_Add_name );ET_NO = (TextView) findViewById(R.id. ET_Add_NO );ET_Pro = (TextView) findViewById(R.
25、id. ET_Add_Pro );ET_Age = (TextView) findViewById(R.id. ET_Add_Age );rg = (RadioGroup) findViewById(R.id. rg );rg .setOnCheckedChangeListener( new OnCheckedChangeListener()public void onCheckedChanged(RadioGroup group, intCheckedId)radio_sex = CheckedId = R.id. rad_male ? 男 : 女 ;);/提交操作btn_Accept .s
26、etOnClickListener( new OnClickListener()public void onClick(View source) String name = ET_name .getText().toString();String NO = ET_NO .getText().toString();String sex = radio_sex ;String pro = ET_Pro .getText().toString();12String age = ET_Age .getText().toString();/规范性与完好性判断try/ 插入数据db .execSQL( i
27、nsert into studentvalues( ?, ?, ?, ?, ?) , new String name, NO, sex, pro, age);/ 规范性与完好性判断catch (SQLiteException e)Toast. makeText (Add. this , 插入数据失败,请检查数据规范性与学号的独一性 , Toast. LENGTH_SHORT ).show();return ;Toast. makeText (Add. this , 成功插入一条数据: +n +name+ n +NO+n +sex+ n +pro+ n +age, Toast. LENGTH_SHORT ).show(););btn_Cancle .setOnClickListener( new OnClickListener()public void onClick(View source) db .close();finish(););4.改正数据界面:13查找界面:对文本框内输入的数据进行精准查找,成功后转入改正界面改正界面:14文本框内默认显示以前的数据,改正达成点击确立以文本框内的信息对数据进行更新中心代码:查找:btn_Accept .setOnClickListener(
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2