Android 實例開發一個學生管理系統流程詳解

效果演示

隨手做的一個小玩意,還有很多功能沒有完善,倘有疏漏,萬望海涵。

在這裡插入圖片描述

實現功能總覽

實現瞭登錄、註冊、忘記密碼、成績查詢、考勤情況、課表查看、提交作業、課程打卡等。

代碼

登錄與忘記密碼界面

登錄與忘記密碼界面采用的是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 學生管理系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: