Android 实例开发一个学生管理系统流程详解
程序员文章站
2022-03-28 22:06:00
目录效果演示实现功能总览代码登录与忘记密码界面一、添加布局文件二、添加标题文字三、绑定适配器注册界面一、创建两个drawable文件二、将其添加数组内三、动态变化背景考勤界面一、circleprogr...
效果演示
随手做的一个小玩意,还有很多功能没有完善,倘有疏漏,万望海涵。
实现功能总览
实现了登录、注册、忘记密码、成绩查询、考勤情况、课表查看、提交作业、课程打卡等。
代码
登录与忘记密码界面
登录与忘记密码界面采用的是tablayout+viewpager+pageradapter实现的
一、添加布局文件
view view_homepager = layoutinflater.from( student.this ).inflate( r.layout.homeppage_item,null,false ); view view_data = layoutinflater.from( student.this ).inflate( r.layout.data_item,null,false ); view view_course = layoutinflater.from( student.this ).inflate( r.layout.course_item,null,false ); view view_my = layoutinflater.from( student.this ).inflate( r.layout.my_item,null,false );
private list<view> views = new arraylist<>( );
views.add( view_homepager ); views.add( view_data ); views.add( view_course ); views.add( view_my );
二、添加标题文字
private list<string> titles = new arraylist<>( );
titles.add( "首页" ); titles.add( "数据" ); titles.add( "课程" ); titles.add( "我的" );
三、绑定适配器
/*pageradapter 适配器代码如下*/ public class viewpageradapter extends pageradapter { private list<view> views; private list<string> titles; public viewpageradapter(list<view> views,list<string> titles){ this.views = views; this.titles = titles; } @override public int getcount() { return views.size(); } @override public boolean isviewfromobject(@nonnull view view, @nonnull object object) { return view == object; } @nonnull @override public object instantiateitem(@nonnull viewgroup container, int position) { container.addview( views.get( position ) ); return views.get( position ); } @override public void destroyitem(@nonnull viewgroup container, int position, @nonnull object object) { container.removeview( views.get( position ) ); } @nullable @override public charsequence getpagetitle(int position) { return titles.get( position ); } }
viewpageradapter adapter = new viewpageradapter( views,titles ); for (string title : titles){ title.addtab( title.newtab().settext( title ) ); } title.setupwithviewpager( viewpager ); viewpager.setadapter( adapter );
注册界面
一、创建两个drawable文件
其一
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#63b8ff"/> <size android:width="20dp" android:height="20dp"/> </shape>
其二
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ffffff"/> <size android:height="20dp" android:width="20dp"/> <stroke android:width="1dp" android:color="#eaeaea"/> </shape>
二、将其添加数组内
private final int[] identity = {r.drawable.press_oval_textview,r.drawable.notpress_oval_textview};
三、动态变化背景
private void selectstudent(){ midentity_student.setbackgroundresource( identity[0] ); midentity_teacher.setbackgroundresource( identity[1] ); } private void selectteacher(){ midentity_student.setbackgroundresource( identity[1] ); midentity_teacher.setbackgroundresource( identity[0] ); }
考勤界面
主要是通过绘制一个圆,圆环、内圆、文字分别使用不同的背景颜色,并将修改背景颜色的接口暴露出来。
一、circleprogressbar代码如下
public class circleprogressbar extends view { // 画实心圆的画笔 private paint mcirclepaint; // 画圆环的画笔 private paint mringpaint; // 画圆环的画笔背景色 private paint mringpaintbg; // 画字体的画笔 private paint mtextpaint; // 圆形颜色 private int mcirclecolor; // 圆环颜色 private int mringcolor; // 圆环背景颜色 private int mringbgcolor; // 半径 private float mradius; // 圆环半径 private float mringradius; // 圆环宽度 private float mstrokewidth; // 圆心x坐标 private int mxcenter; // 圆心y坐标 private int mycenter; // 字的长度 private float mtxtwidth; // 字的高度 private float mtxtheight; // 总进度 private int mtotalprogress = 100; // 当前进度 private double mprogress; public circleprogressbar(context context) { super( context ); } public circleprogressbar(context context, @nullable attributeset attrs) { super( context, attrs ); initattrs(context,attrs); initvariable(); } public circleprogressbar(context context, @nullable attributeset attrs, int defstyleattr) { super( context, attrs, defstyleattr ); } private void initattrs(context context, attributeset attrs) { typedarray typearray = context.gettheme().obtainstyledattributes(attrs, r.styleable.taskscompletedview, 0, 0); mradius = typearray.getdimension(r.styleable.taskscompletedview_radius, 80); mstrokewidth = typearray.getdimension(r.styleable.taskscompletedview_strokewidth, 10); mcirclecolor = typearray.getcolor(r.styleable.taskscompletedview_circlecolor, 0xffffffff); mringcolor = typearray.getcolor(r.styleable.taskscompletedview_ringcolor, 0xffffffff); mringbgcolor = typearray.getcolor(r.styleable.taskscompletedview_ringbgcolor, 0xffffffff); mringradius = mradius + mstrokewidth / 2; } private void initvariable() { //内圆 mcirclepaint = new paint(); mcirclepaint.setantialias(true); mcirclepaint.setcolor(mcirclecolor); mcirclepaint.setstyle(paint.style.fill); //外圆弧背景 mringpaintbg = new paint(); mringpaintbg.setantialias(true); mringpaintbg.setcolor(mringbgcolor); mringpaintbg.setstyle(paint.style.stroke); mringpaintbg.setstrokewidth(mstrokewidth); //外圆弧 mringpaint = new paint(); mringpaint.setantialias(true); mringpaint.setcolor(mringcolor); mringpaint.setstyle(paint.style.stroke); mringpaint.setstrokewidth(mstrokewidth); //mringpaint.setstrokecap(paint.cap.round);//设置线冒样式,有圆 有方 //中间字 mtextpaint = new paint(); mtextpaint.setantialias(true); mtextpaint.setstyle(paint.style.fill); mtextpaint.setcolor(mringcolor); mtextpaint.settextsize(mradius / 2); paint.fontmetrics fm = mtextpaint.getfontmetrics(); mtxtheight = (int) math.ceil(fm.descent - fm.ascent); } @override protected void ondraw(canvas canvas) { super.ondraw( canvas ); mxcenter = getwidth() / 2; mycenter = getheight() / 2; //内圆 canvas.drawcircle( mxcenter, mycenter, mradius, mcirclepaint ); //外圆弧背景 rectf oval1 = new rectf(); oval1.left = (mxcenter - mringradius); oval1.top = (mycenter - mringradius); oval1.right = mringradius * 2 + (mxcenter - mringradius); oval1.bottom = mringradius * 2 + (mycenter - mringradius); canvas.drawarc( oval1, 0, 360, false, mringpaintbg ); //圆弧所在的椭圆对象、圆弧的起始角度、圆弧的角度、是否显示半径连线 //外圆弧 if (mprogress > 0) { rectf oval = new rectf(); oval.left = (mxcenter - mringradius); oval.top = (mycenter - mringradius); oval.right = mringradius * 2 + (mxcenter - mringradius); oval.bottom = mringradius * 2 + (mycenter - mringradius); canvas.drawarc( oval, -90, ((float) mprogress / mtotalprogress) * 360, false, mringpaint ); // //字体 string txt = mprogress + "%"; mtxtwidth = mtextpaint.measuretext( txt, 0, txt.length() ); canvas.drawtext( txt, mxcenter - mtxtwidth / 2, mycenter + mtxtheight / 4, mtextpaint ); } } //设置进度 public void setprogress(double progress) { mprogress = progress; postinvalidate();//重绘 } public void setcirclecolor(int color){ mringpaint.setcolor( color ); postinvalidate();//重绘 } }
签到界面
签到界面就倒计时和位置签到
一、倒计时
采用的是thread+handler
在子线程内总共发生两种标志至handler内,0x00表示倒计时未完成,0x01表示倒计时完成。
private void countdown(){ new thread( ){ @override public void run() { super.run(); for (int j = 14; j >= 0 ; j--) { for (int i = 59; i >= 0; i--) { message message = handler.obtainmessage(); message.what = 0x00; message.arg1 = i; message.arg2 = j; handler.sendmessage( message ); try { thread.sleep( 1000 ); } catch (interruptedexception e) { e.printstacktrace(); } } } message message = handler.obtainmessage( ); message.what = 0x01; handler.sendmessage( message ); } }.start(); }
final handler handler = new handler( ){ @override public void handlemessage(@nonnull message msg) { super.handlemessage( msg ); switch (msg.what){ case 0x00: if (msg.arg2 >= 10){ signinminutes.settext( msg.arg2+":" ); }else if (msg.arg2 < 10 && msg.arg2 > 0){ signinminutes.settext( "0"+msg.arg2+":" ); }else { signinminutes.settext( "00"+":" ); } if (msg.arg1 >= 10){ signinseconds.settext( msg.arg1+"" ); }else if (msg.arg1 < 10 && msg.arg1 > 0){ signinseconds.settext( "0"+msg.arg1 ); }else { signinseconds.settext( "00" ); } break; case 0x01: signinseconds.settext( "00" ); signinminutes.settext( "00:" ); break; } } };
二、位置签到
位置签到采用的是百度地图sdk
public class locationcheckin extends appcompatactivity { private mapview baidumapview; private textview currentposition,mlatitude,mlongitude,currentdate,signinposition; private button submitmessage,successsignin; private imageview locationsignin_exit; private view view = null; private popupwindow mpopupwindow; private locationclient client; private baidumap mbaidumap; private double latitude = 0; private double longitude = 0; private boolean isfirstlocate = true; @override protected void oncreate(bundle savedinstancestate) { super.oncreate( savedinstancestate ); if (build.version.sdk_int >= 21) { view decorview = getwindow().getdecorview(); decorview.setsystemuivisibility( view.system_ui_flag_layout_fullscreen | view.system_ui_flag_layout_stable ); getwindow().setstatusbarcolor( color.transparent ); } sdkinitializer.initialize( getapplicationcontext() ); client = new locationclient( getapplicationcontext() );//获取全局context client.registerlocationlistener( new mybaidumap() );//注册一个定位监听器,获取位置信息,回调此定位监听器 setcontentview( r.layout.activity_location_check_in ); initview(); initbaidumap(); initpermission(); initpopwindows(); listener(); } private void initview(){ baidumapview = findviewbyid( r.id.baidu_mapview ); currentposition = findviewbyid( r.id.currentposition ); submitmessage = findviewbyid( r.id.submitmessage ); mlatitude = findviewbyid( r.id.latitude ); mlongitude = findviewbyid( r.id.longitude ); locationsignin_exit = findviewbyid( r.id.locationsignin_exit ); } private void initpopwindows(){ view = layoutinflater.from( locationcheckin.this ).inflate( r.layout.signin_success ,null,false); currentdate = view.findviewbyid( r.id.currentdate ); signinposition = view.findviewbyid( r.id.signinposition ); successsignin = view.findviewbyid( r.id.success); mpopupwindow = new popupwindow( view, viewgroup.layoutparams.match_parent,viewgroup.layoutparams.wrap_content ); mpopupwindow.setfocusable( true ); //获取焦点 mpopupwindow.setbackgrounddrawable( new bitmapdrawable() ); mpopupwindow.setoutsidetouchable( true ); //点击外面地方,取消 mpopupwindow.settouchable( true ); //允许点击 mpopupwindow.setanimationstyle( r.style.mypopupwindow ); //设置动画 calendar calendar = calendar.getinstance(); int hour = calendar.get( calendar.hour_of_day ); int minute = calendar.get( calendar.minute ); string shour,sminute; if (hour < 10){ shour = "0"+hour; }else { shour = ""+hour; } if (minute < 10){ sminute = "0"+minute; }else { sminute = ""+minute; } currentdate.settext( shour+":"+sminute ); //signinposition.settext( position+"000"); successsignin.setonclicklistener( new view.onclicklistener() { @override public void onclick(view v) { mpopupwindow.dismiss(); } } ); } private void showpopwindows(){ mpopupwindow.showatlocation( view, gravity.center,0,0 ); } private void initbaidumap(){ /*百度地图初始化*/ mbaidumap = baidumapview.getmap();//获取实例,可以对地图进行一系列操作,比如:缩放范围,移动地图 mbaidumap.setmylocationenabled(true);//允许当前设备显示在地图上 } private void navigateto(bdlocation location){ if (isfirstlocate){ latlng lng = new latlng(location.getlatitude(),location.getlongitude());//指定经纬度 mapstatusupdate update = mapstatusupdatefactory.newlatlng(lng); mbaidumap.animatemapstatus(update); update = mapstatusupdatefactory.zoomto(16f);//百度地图缩放级别限定在3-19 mbaidumap.animatemapstatus(update); isfirstlocate = false; } mylocationdata.builder builder = new mylocationdata.builder(); builder.latitude(location.getlatitude());//纬度 builder.longitude(location.getlongitude());//经度 mylocationdata locationdata = builder.build(); mbaidumap.setmylocationdata(locationdata); } private void initpermission(){ list<string> permissionlist = new arraylist<>(); //判断权限是否授权 if (contextcompat.checkselfpermission( locationcheckin.this, manifest.permission.access_fine_location ) != packagemanager.permission_granted) { permissionlist.add( manifest.permission.access_fine_location ); } if (contextcompat.checkselfpermission( locationcheckin.this, manifest.permission.read_phone_state ) != packagemanager.permission_granted) { permissionlist.add( manifest.permission.read_phone_state ); } if (contextcompat.checkselfpermission( locationcheckin.this, manifest.permission.write_external_storage ) != packagemanager.permission_granted) { permissionlist.add( manifest.permission.write_external_storage ); } if (!permissionlist.isempty()) { string[] permissions = permissionlist.toarray( new string[permissionlist.size()] );//转化为数组 activitycompat.requestpermissions( locationcheckin.this, permissions, 1 );//一次性申请权限 } else { /*****************如果权限都已经声明,开始配置参数*****************/ requestlocation(); } } //执行 private void requestlocation(){ initlocation(); client.start(); } /*******************初始化百度地图各种参数*******************/ public void initlocation() { locationclientoption option = new locationclientoption(); option.setlocationmode(locationclientoption.locationmode.hight_accuracy); /**可选,设置定位模式,默认高精度locationmode.hight_accuracy:高精度; * locationmode. battery_saving:低功耗;locationmode. device_sensors:仅使用设备;*/ option.setcoortype("bd09ll"); /**可选,设置返回经纬度坐标类型,默认gcj02gcj02:国测局坐标;bd09ll:百度经纬度坐标;bd09:百度墨卡托坐标; 海外地区定位,无需设置坐标类型,统一返回wgs84类型坐标*/ option.setscanspan(3000); /**可选,设置发起定位请求的间隔,int类型,单位ms如果设置为0,则代表单次定位,即仅定位一次,默认为0如果设置非0,需设置1000ms以上才有效*/ option.setopengps(true); /**可选,设置是否使用gps,默认false使用高精度和仅用设备两种定位模式的,参数必须设置为true*/ option.setlocationnotify(true); /**可选,设置是否当gps有效时按照1s/1次频率输出gps结果,默认false*/ option.setignorekillprocess(false); /**定位sdk内部是一个service,并放到了独立进程。设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setignorekillprocess(true)*/ option.setignorecacheexception(false); /**可选,设置是否收集crash信息,默认收集,即参数为false*/ option.setisneedaltitude(true);/**设置海拔高度*/ option.setwificachetimeout(5 * 60 * 1000); /**可选,7.2版本新增能力如果设置了该接口,首次启动定位时,会先判断当前wifi是否超出有效期,若超出有效期,会先重新扫描wifi,然后定位*/ option.setenablesimulategps(false); /**可选,设置是否需要过滤gps仿真结果,默认需要,即参数为false*/ option.setisneedaddress(true); /**可选,设置是否需要地址信息,默认不需要*/ client.setlocoption(option); /**mlocationclient为第二步初始化过的locationclient对象需将配置好的locationclientoption对象,通过setlocoption方法传递给locationclient对象使用*/ } class mybaidumap implements bdlocationlistener { @override public void onreceivelocation(bdlocation bdlocation) { latitude = bdlocation.getlatitude();//获取纬度 longitude = bdlocation.getlongitude();//获取经度 mlatitude.settext( latitude+"" ); mlongitude.settext( longitude+"" ); double radius = bdlocation.getradius(); if (bdlocation.getloctype() == bdlocation.typegpslocation || bdlocation.getloctype() == bdlocation.typenetworklocation){ navigateto(bdlocation); } //stringbuilder currentposition = new stringbuilder(); stringbuilder currentcity = new stringbuilder( ); stringbuilder position = new stringbuilder( ); //currentposition.append("纬度:").append(bdlocation.getlatitude()).append("\n"); // currentposition.append("经度:").append(bdlocation.getlongitude()).append("\n"); /* currentposition.append("国家:").append(bdlocation.getcountry()).append("\n"); currentposition.append("省:").append(bdlocation.getprovince()).append("\n"); currentposition.append("市/县:").append(bdlocation.getcity()).append("\n"); currentposition.append("区/乡:").append(bdlocation.getdistrict()).append("\n"); currentposition.append("街道/村:").append(bdlocation.getstreet()).append("\n");*/ // currentposition.append("定位方式:"); //currentposition.append( bdlocation.getprovince() ); // position.append( bdlocation.getcity() ); position.append( bdlocation.getdistrict() ); position.append( bdlocation.getstreet() ); currentcity.append( bdlocation.getprovince() ); currentcity.append( bdlocation.getcity() ); currentcity.append( bdlocation.getdistrict() ); currentcity.append( bdlocation.getstreet() ); /*if (bdlocation.getloctype() == bdlocation.typegpslocation){ //currentposition.append("gps"); }else if (bdlocation.getloctype() == bdlocation.typenetworklocation){ //currentposition.append("网络"); }*/ /* currentcity.append( bdlocation.getcity() );*/ //mupdateposition = currentposition+""; currentposition.settext( currentcity ); signinposition.settext( position); //position = currentposition.gettext().tostring()+""; //function_cityname.settext( currentcity ); } } private void listener(){ onclick onclick = new onclick(); submitmessage.setonclicklistener( onclick ); locationsignin_exit.setonclicklistener( onclick ); } class onclick implements view.onclicklistener{ @override public void onclick(view v) { switch (v.getid()){ case r.id.submitmessage: showpopwindows(); break; case r.id.locationsignin_exit: startactivity( new intent( locationcheckin.this,signin.class ) ); } } } }
成绩查询界面
采用的是md的cardstackview,需要实现一个adapter适配器,此适配器与recyclerview适配器构建类似
一、创建stackadapter 适配器
package com.franzliszt.student.queryscore; public class stackadapter extends com.loopeer.cardstack.stackadapter<integer> { public stackadapter(context context) { super(context); } @override public void bindview(integer data, int position, cardstackview.viewholder holder) { if (holder instanceof coloritemlargeheaderviewholder) { coloritemlargeheaderviewholder h = (coloritemlargeheaderviewholder) holder; h.onbind(data, position); } if (holder instanceof coloritemwithnoheaderviewholder) { coloritemwithnoheaderviewholder h = (coloritemwithnoheaderviewholder) holder; h.onbind(data, position); } if (holder instanceof coloritemviewholder) { coloritemviewholder h = (coloritemviewholder) holder; h.onbind(data, position); } } @override protected cardstackview.viewholder oncreateview(viewgroup parent, int viewtype) { view view; switch (viewtype) { case r.layout.list_card_item_larger_header: view = getlayoutinflater().inflate(r.layout.list_card_item_larger_header, parent, false); return new coloritemlargeheaderviewholder(view); case r.layout.list_card_item_with_no_header: view = getlayoutinflater().inflate(r.layout.list_card_item_with_no_header, parent, false); return new coloritemwithnoheaderviewholder(view); case r.layout.other_item: view = getlayoutinflater().inflate(r.layout.other_item, parent, false); return new coloritemviewholder(view); case r.layout.other_item_thank: view = getlayoutinflater().inflate(r.layout.other_item_thank, parent, false); return new coloritemviewholder(view); case r.layout.other_item_note_1: view = getlayoutinflater().inflate(r.layout.other_item_note_1, parent, false); return new coloritemviewholder(view); case r.layout.other_item_note_2: view = getlayoutinflater().inflate(r.layout.other_item_note_2, parent, false); return new coloritemviewholder(view); default: view = getlayoutinflater().inflate(r.layout.first_semester, parent, false); return new coloritemviewholder(view); } } @override public int getitemviewtype(int position) { if (position == 6 ){//todo test larger item return r.layout.other_item; } else if (position == 7){ return r.layout.other_item_thank; }else if (position == 8){ return r.layout.other_item_note_1; }else if (position == 9){ return r.layout.other_item_note_2; } else { return r.layout.first_semester; } } static class coloritemviewholder extends cardstackview.viewholder { view mlayout; view mcontainercontent; textview mtexttitle; textview classname1,classstatus1,classmethod1,classflag1,credit1,gradepoint1; textview classname2,classstatus2,classmethod2,classflag2,credit2,gradepoint2; textview classname3,classstatus3,classmethod3,classflag3,credit3,gradepoint3; textview classname4,classstatus4,classmethod4,classflag4,credit4,gradepoint4; textview titlecontent,moreinfo; public coloritemviewholder(view view) { super(view); mlayout = view.findviewbyid(r.id.frame_list_card_item); mcontainercontent = view.findviewbyid(r.id.container_list_content); mtexttitle = view.findviewbyid(r.id.text_list_card_title); titlecontent = view.findviewbyid( r.id.titlecontent ); moreinfo = view.findviewbyid( r.id.moreinfo ); classname1 = view.findviewbyid(r.id.classname1); classstatus1 = view.findviewbyid(r.id.classstatus1); classmethod1 = view.findviewbyid(r.id.classmethod1); classflag1 = view.findviewbyid(r.id.classflag1); credit1 = view.findviewbyid(r.id.credit1); gradepoint1= view.findviewbyid(r.id.gradepoint1); classname2 = view.findviewbyid(r.id.classname2); classstatus2 = view.findviewbyid(r.id.classstatus2); classmethod2 = view.findviewbyid(r.id.classmethod2); classflag2 = view.findviewbyid(r.id.classflag2); credit2 = view.findviewbyid(r.id.credit2); gradepoint2= view.findviewbyid(r.id.gradepoint2); classname3 = view.findviewbyid(r.id.classname3); classstatus3 = view.findviewbyid(r.id.classstatus3); classmethod3 = view.findviewbyid(r.id.classmethod3); classflag3 = view.findviewbyid(r.id.classflag3); credit3 = view.findviewbyid(r.id.credit3); gradepoint3= view.findviewbyid(r.id.gradepoint3); classname4 = view.findviewbyid(r.id.classname4); classstatus4 = view.findviewbyid(r.id.classstatus4); classmethod4 = view.findviewbyid(r.id.classmethod4); classflag4 = view.findviewbyid(r.id.classflag4); credit4 = view.findviewbyid(r.id.credit4); gradepoint4 = view.findviewbyid(r.id.gradepoint4); } @override public void onitemexpand(boolean b) { mcontainercontent.setvisibility(b ? view.visible : view.gone); } public void onbind(integer data, int position) { mlayout.getbackground().setcolorfilter( contextcompat.getcolor(getcontext(), data), porterduff.mode.src_in); //mtexttitle.settext( string.valueof(position)); if (position == 0){ mtexttitle.settext( "2019-2020第一学期"); classname1.settext( "物联网概论" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 3.0" ); gradepoint1.settext( "绩点: 3.0" ); classname2.settext( "应用数学" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 3.0" ); gradepoint2.settext( "绩点: 2.0" ); classname3.settext( "大学英语" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 3.0" ); gradepoint3.settext( "绩点: 1.0" ); classname4.settext( "军事理论" ); classstatus4.settext( "选修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 2.0" ); gradepoint4.settext( "绩点: 3.0" ); }else if (position == 1){ mtexttitle.settext( "2019-2020第二学期"); classname1.settext( "电子技术" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 4.0" ); gradepoint1.settext( "绩点: 3.0" ); classname2.settext( "c语言程序设计" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 2.0" ); gradepoint2.settext( "绩点: 4.0" ); classname3.settext( "大学体育" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 1.5" ); gradepoint3.settext( "绩点: 3.0" ); classname4.settext( "音乐鉴赏" ); classstatus4.settext( "选修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 1.5" ); gradepoint4.settext( "绩点: 3.0" ); }else if (position == 2){ mtexttitle.settext( "2020-2021第一学期"); classname1.settext( "单片机技术应用" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 4.5" ); gradepoint1.settext( "绩点: 4.0" ); classname2.settext( "java程序设计" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 1.0" ); gradepoint2.settext( "绩点: 3.0" ); classname3.settext( "自动识别技术" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 4.5" ); gradepoint3.settext( "绩点: 4.0" ); classname4.settext( "文化地理" ); classstatus4.settext( "选修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 1.0" ); gradepoint4.settext( "绩点: 4.0" ); }else if (position == 3){ mtexttitle.settext( "2020-2021第二学期"); classname1.settext( "android程序设计" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 1.0" ); gradepoint1.settext( "绩点: 4.0" ); classname2.settext( "无线传感网络技术" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 1.0" ); gradepoint2.settext( "绩点: 4.0" ); classname3.settext( "体育" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 1.5" ); gradepoint3.settext( "绩点: 3.0" ); classname4.settext( "有效沟通技巧" ); classstatus4.settext( "选修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 1.5" ); gradepoint4.settext( "绩点: 3.0" ); }else if (position == 4){ mtexttitle.settext( "2021-2022第一学期"); classname1.settext( "物联网概论" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 3.0" ); gradepoint1.settext( "绩点: 3.0" ); classname2.settext( "应用数学" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 3.0" ); gradepoint2.settext( "绩点: 2.0" ); classname3.settext( "大学英语" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 3.0" ); gradepoint3.settext( "绩点: 1.0" ); classname4.settext( "军事理论" ); classstatus4.settext( "必修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 2.0" ); gradepoint4.settext( "绩点: 3.0" ); }else if (position == 5){ mtexttitle.settext( "2021-2022第二学期"); classname1.settext( "物联网概论" ); classstatus1.settext( "必修课" ); classflag1.settext( "辅修标记: 主修" ); classmethod1.settext( "考核方式: 考试" ); credit1.settext( "学分: 3.0" ); gradepoint1.settext( "绩点: 3.0" ); classname2.settext( "应用数学" ); classstatus2.settext( "必修课" ); classflag2.settext( "辅修标记: 主修" ); classmethod2.settext( "考核方式: 考试" ); credit2.settext( "学分: 3.0" ); gradepoint2.settext( "绩点: 2.0" ); classname3.settext( "大学英语" ); classstatus3.settext( "必修课" ); classflag3.settext( "辅修标记: 主修" ); classmethod3.settext( "考核方式: 考试" ); credit3.settext( "学分: 3.0" ); gradepoint3.settext( "绩点: 1.0" ); classname4.settext( "军事理论" ); classstatus4.settext( "必修课" ); classflag4.settext( "辅修标记: 主修" ); classmethod4.settext( "考核方式: 考查" ); credit4.settext( "学分: 2.0" ); gradepoint4.settext( "绩点: 3.0" ); }else if (position == 6){ mtexttitle.settext( "毕业设计"); }else if (position == 7){ mtexttitle.settext( "致谢"); }else if (position == 8){ mtexttitle.settext( "校园杂记一"); }else if (position == 9){ mtexttitle.settext( "校园杂记二"); }else { mtexttitle.settext( string.valueof(position)); } } } static class coloritemwithnoheaderviewholder extends cardstackview.viewholder { view mlayout; textview mtexttitle; public coloritemwithnoheaderviewholder(view view) { super(view); mlayout = view.findviewbyid(r.id.frame_list_card_item); mtexttitle = (textview) view.findviewbyid(r.id.text_list_card_title); } @override public void onitemexpand(boolean b) { } public void onbind(integer data, int position) { mlayout.getbackground().setcolorfilter(contextcompat.getcolor(getcontext(), data), porterduff.mode.src_in); mtexttitle.settext( string.valueof(position)); } } static class coloritemlargeheaderviewholder extends cardstackview.viewholder { view mlayout; view mcontainercontent; textview mtexttitle; public coloritemlargeheaderviewholder(view view) { super(view); mlayout = view.findviewbyid(r.id.frame_list_card_item); mcontainercontent = view.findviewbyid(r.id.container_list_content); mtexttitle = view.findviewbyid(r.id.text_list_card_title); } @override public void onitemexpand(boolean b) { mcontainercontent.setvisibility(b ? view.visible : view.gone); } @override protected void onanimationstatechange(int state, boolean willbeselect) { super.onanimationstatechange(state, willbeselect); if (state == cardstackview.animation_state_start && willbeselect) { onitemexpand(true); } if (state == cardstackview.animation_state_end && !willbeselect) { onitemexpand(false); } } public void onbind(integer data, int position) { mlayout.getbackground().setcolorfilter(contextcompat.getcolor(getcontext(), data), porterduff.mode.src_in); mtexttitle.settext( string.valueof(position)); mtexttitle.settext( "2019-2020第一学期"); itemview.findviewbyid(r.id.text_view).setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ((cardstackview)itemview.getparent()).performitemclick(coloritemlargeheaderviewholder.this); } }); } } }
二、绑定适配器
queryscorecardstackview.setitemexpendlistener( this ); adapter = new stackadapter( this ); queryscorecardstackview.setadapter( adapter );
三、为每一个子项添加背景色
public static integer[] color_datas = new integer[]{ r.color.color_1, r.color.color_2, r.color.color_3, r.color.color_4, r.color.color_5, r.color.color_6, r.color.color_7, r.color.color_8, r.color.color_9, r.color.color_10, };
new handler( ).postdelayed( new runnable() { @override public void run() { adapter.updatedata( arrays.aslist( color_datas ) ); } } ,200);
到此这篇关于android 实例开发一个学生管理系统流程详解的文章就介绍到这了,更多相关android 学生管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 移动广告平台试玩互动完成数千万元Pre-A 轮融资
下一篇: 古代太监为何抢着去冷宫当差?不晦气吗