while循环不能在我的代码中工作。我尝试过diff方法,但无法实现我的代码

时间:2016-02-15 18:40:45

标签: android while-loop

package com.example.gopipatel.essar_shift_schedule;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Handler;
import java.util.logging.LogRecord;


public class MainActivity extends Activity {

    LinearLayout ll1,ll2,ll3,ll4,ll5;
    RadioGroup rg_Shift;
    RadioButton rb_A,rb_B,rb_C;
    Button btn_Set_Date,btn_Get_Your_Shift;
    TextView txt_Start_Date,txt_End_Date,txt_Your_Shift;

    String Shift_Selected;
    int Selected_Shift_Id;

    Calendar Set_Calander = Calendar.getInstance();
    Calendar Today_Calander=Calendar.getInstance();

/ *

我的代码是在选定日期获得轮班任务。

每个星期五的班次变化。换班顺序是A-C-B-A ..

我只是希望用户输入该日期,并在今天班次用户的帮助下获得当天预期的班次。

* /         @覆盖         public void onCreate(Bundle icicle)         {             super.onCreate(冰柱);             的setContentView(R.layout.activity_main);

        ll1=(LinearLayout)findViewById(R.id.ll1);
        ll2=(LinearLayout)findViewById(R.id.ll2);
        ll3=(LinearLayout)findViewById(R.id.ll3);
        ll4=(LinearLayout)findViewById(R.id.ll4);
        ll5=(LinearLayout)findViewById(R.id.ll5);
        rg_Shift=(RadioGroup)findViewById(R.id.rg_Shift);
        rb_A=(RadioButton)findViewById((R.id.rb_A));
        rb_B=(RadioButton)findViewById((R.id.rb_B));
        rb_C=(RadioButton)findViewById((R.id.rb_C));
        btn_Set_Date=(Button)findViewById(R.id.btn_Set_Date);
        btn_Get_Your_Shift=(Button)findViewById(R.id.btn_Get_Your_Shift);
        txt_Start_Date=(TextView)findViewById(R.id.txt_Start_Date);
        txt_End_Date=(TextView)findViewById(R.id.txt_End_Date);
        txt_Your_Shift=(TextView)findViewById(R.id.txt_Your_Shift);

        Selected_Shift_Id = rg_Shift.getCheckedRadioButtonId();

        Shift_Selected = "";
        switch (Selected_Shift_Id)
        {
            case R.id.rb_A: Shift_Selected = "A";
                break;
            case R.id.rb_B: Shift_Selected = "B";
                break;
            case R.id.rb_C: Shift_Selected = "C";
                break;
        }

        btn_Set_Date.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                new DatePickerDialog(MainActivity.this, d, Set_Calander.get(Calendar.YEAR), Set_Calander.get(Calendar.MONTH), Set_Calander.get(Calendar.DAY_OF_MONTH)).show();
                updateDate();
            }
        });

        btn_Get_Your_Shift.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                Time_to_Calculate TOC=new Time_to_Calculate(Today_Calander,Shift_Selected,Set_Calander);
                TOC.execute();

            }
        });



    };

    public DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
        {
            Set_Calander.set(Calendar.YEAR, year);
            Set_Calander.set(Calendar.MONTH, monthOfYear);
            Set_Calander.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateDate();
        }
    };

    public void updateDate()
    {
        txt_Start_Date.setText(Today_Calander.getTime().toString());
        txt_End_Date.setText(Set_Calander.getTime().toString());

    }


    private class Time_to_Calculate extends AsyncTask<Calendar,String,Calendar>
    {
        private Calendar Temp_Calander,private_Today_Calander,private_Set_Calander;
        private int isFriday,Friday=0,i;
        private String private_Shift_Selected,Your_Shift;


        public Time_to_Calculate(Calendar private_today_calander,String private_shift_selected,Calendar private_set_calander)
        {
            private_Set_Calander=private_set_calander;
            private_Today_Calander=private_set_calander;
            private_Shift_Selected=private_shift_selected;
        }

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
        }

        @Override
        protected Calendar doInBackground(Calendar... params)
        {

            while (private_Today_Calander!=private_Set_Calander)
            {
                Temp_Calander=private_Today_Calander;
                Temp_Calander.add(Calendar.DATE, 1);
                isFriday=Temp_Calander.get(Calendar.DAY_OF_WEEK);
                if (isFriday==6)
                {
                    Friday++;
                }
            }

            if (Friday==0)
            {
                Your_Shift=private_Shift_Selected;
            }
            else
            {
                for (i=1;i<=Friday;i++)
                {
                    if(private_Shift_Selected=="A")
                    {Your_Shift="C";}
                    else if(private_Shift_Selected=="B")
                    {Your_Shift="A";}
                    else  if (private_Shift_Selected=="C")
                    {Your_Shift="B";}
                }
            }

            return null;
        }

        @Override
        protected void onProgressUpdate(String... values)
        {
            Toast.makeText(MainActivity.this,"Processing....",Toast.LENGTH_LONG).show();
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(Calendar calendar)
        {
            txt_Your_Shift.setText(Your_Shift);
            super.onPostExecute(calendar);
        }


    }


}

1 个答案:

答案 0 :(得分:0)

您初始化private_Today_Calander&amp; private_Set_Calanderprivate_set_calander所以while循环体永远不会被执行 您可能需要使用private_Today_Calander

初始化private_today_Calander