Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 再次关闭并打开应用程序后,我的代码未刷新屏幕_Android - Fatal编程技术网

Android 再次关闭并打开应用程序后,我的代码未刷新屏幕

Android 再次关闭并打开应用程序后,我的代码未刷新屏幕,android,Android,下面是我的代码,代码运行时第一次完美运行显示本周查看此图像完美显示今天是7月28日星期日查看此图像移动时查看前一周查看此图像完美显示当我关闭应用程序并重新启动时再次显示此上周屏幕而不是本周屏幕。它的意思是它保持最后的状态,我如何在每次应用程序启动时刷新日历??下面是我的完整代码 public class HoyahCalendar extends Activity { private static int mYear; public static int currentIndex = -

下面是我的代码,代码运行时第一次完美运行显示本周查看此图像完美显示今天是7月28日星期日查看此图像移动时查看前一周查看此图像完美显示当我关闭应用程序并重新启动时再次显示此上周屏幕而不是本周屏幕。它的意思是它保持最后的状态,我如何在每次应用程序启动时刷新日历??下面是我的完整代码

    public class HoyahCalendar extends Activity {
private static int mYear;
public static int currentIndex = -1;
private static int mMonth;
public static int mDay;
public static String[][] a = new String[6][7];
private TextView date_today;
ImageButton last_month;
ImageButton next_month;

private ImageButton last_week;
private ImageButton next_week;

private TextView e00;
private TextView e01;
private TextView e02;
private TextView e03;
private TextView e04;
private TextView e05;
private TextView e06;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    date_today = (TextView) findViewById(R.id.date_today);
    last_month = (ImageButton) findViewById(R.id.last_month);
    next_month = (ImageButton) findViewById(R.id.next_month);
    last_week = (ImageButton) findViewById(R.id.last_week);
    next_week = (ImageButton) findViewById(R.id.next_week);

    e00 = (TextView) findViewById(R.id.e00);
    e01 = (TextView) findViewById(R.id.e01);
    e02 = (TextView) findViewById(R.id.e02);
    e03 = (TextView) findViewById(R.id.e03);
    e04 = (TextView) findViewById(R.id.e04);
    e05 = (TextView) findViewById(R.id.e05);
    e06 = (TextView) findViewById(R.id.e06);

    Calendar mCalendar = Calendar.getInstance();
    mYear = mCalendar.get(Calendar.YEAR);
    mMonth = mCalendar.get(Calendar.MONTH) + 1;
    mDay = mCalendar.get(Calendar.DAY_OF_MONTH);

    // / setListeners();

    last_month.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mMonth == 1) {
                mYear -= 1;
                mMonth = 12;
                new ShowCalendar(mYear, mMonth);
                showOnScreen();
            } else {
                mMonth -= 1;
                new ShowCalendar(mYear, mMonth);
                showOnScreen();
            }

        }
    });

    next_month.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mMonth == 12) {
                mYear += 1;
                mMonth = 1;
                new ShowCalendar(mYear, mMonth);
                showOnScreen();
            } else {
                mMonth += 1;
                new ShowCalendar(mYear, mMonth);
                showOnScreen();
            }

        }
    });

    last_week.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (mMonth == 1) {
                mYear -= 1;
                mMonth = 12;
                new ShowCalendar(mYear, mMonth, mDay, "last");
                showOnScreen();
            } else {
                // mMonth -= 1;
                new ShowCalendar(mYear, mMonth, mDay, "last");
                showOnScreen();
            }
        }
    });

    next_week.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mMonth == 12) {
                mYear += 1;
                mMonth = 1;
                new ShowCalendar(mYear, mMonth, mDay, "next");
                showOnScreen();
            } else {
                if (HoyahCalendar.currentIndex == 4) {
                    HoyahCalendar.currentIndex = 4;
                    // mMonth += 1;
                }

                new ShowCalendar(mYear, mMonth, mDay, "next");
                showOnScreen();
            }

        }
    });

    new ShowCalendar(mYear, mMonth);
    showOnScreen();

}

public void showOnScreen() {

    date_today.setText(mYear + "Years" + mMonth + "Month");
    e00.setText("" + a[0][0]);
    e01.setText("" + a[0][1]);
    e02.setText("" + a[0][2]);
    e03.setText("" + a[0][3]);
    e04.setText("" + a[0][4]);
    e05.setText("" + a[0][5]);
    e06.setText("" + a[0][6]);

}
 }





                 public class ShowCalendar {
private int mYear;
private int mMonth;
private int mDay;
public ShowCalendar(int mYear, int mMonth){
    this.mYear = mYear;
    this.mMonth = mMonth;

    calculateMonthFirstday();
}


public int getmDay() {
    return mDay;
}


public void setmDay(int mDay) {
    this.mDay = mDay;
}


public ShowCalendar(int mYear, int mMonth, int mDay, String time){
    this.mYear = mYear;
    this.mMonth = mMonth;
    if (time == "next"){
        HoyahCalendar.currentIndex++;
        if (HoyahCalendar.currentIndex == 5){
            HoyahCalendar.currentIndex--;
        }
        this.mDay = mDay + 7;
    } else if (time == "last"){
        HoyahCalendar.currentIndex--;
        if (HoyahCalendar.currentIndex == -1){
            HoyahCalendar.currentIndex++;
        }
        this.mDay = mDay - 7;
    }
    calculateMonthFirstday();
}

public void calculateMonthFirstday(){
    int month, first_day=0;
    if((mYear%4==0 && mYear%100!=0)||(mYear%400==0))
        month=1;
    else
        month=0;

    int y, y12, c, c12, m, d;
    y = mYear%100;
    y12 = (mYear-1)%100; //only for January and February
    c = mYear/100;
    c12 = (mYear-1)/100;
    m = mMonth;
    d = 1;

    switch(mMonth){
    case 1: {first_day = y12 + y12/4 +c12/4 - 2*c12 + 26*(13 + 1)/10 + d - 1;break;}
    case 2: {first_day = y12 + y12/4 +c12/4 - 2*c12 + 26*(14 + 1)/10 + d - 1;break;}
    case 4: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 5: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 6: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 7: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 8: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 9: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 10: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 11: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    case 12: {first_day = y + y/4 +c/4 - 2*c + 26*(m + 1)/10 + d - 1;break;}
    }
    if(first_day<0)
        first_day = 7 - (Math.abs(first_day))%7;//first_day每月第一天星期几
    else
        first_day = first_day%7;

    switch(mMonth){
        case 1: {CalculateCalendar(1,first_day,31);break;}
        case 2: {CalculateCalendar(2,first_day,28+month);break;}
        case 3: {CalculateCalendar(3,first_day,31);break;}
        case 4: {CalculateCalendar(4,first_day,30);break;}
        case 5: {CalculateCalendar(5,first_day,31);break;}
        case 6: {CalculateCalendar(6,first_day,30);break;}
        case 7: {CalculateCalendar(7,first_day,31);break;}
        case 8: {CalculateCalendar(8,first_day,31);break;}
        case 9: {CalculateCalendar(9,first_day,30);break;}
        case 10:{CalculateCalendar(10,first_day,31);break;}
        case 11:{CalculateCalendar(11,first_day,30);break;}
        case 12:{CalculateCalendar(12,first_day,31);break;}
    }
}

public void CalculateCalendar(int month_no, int week_no, int month_days){

    int i, s, targetRow = 0;
    int currentDay;
    if (this.mDay == 0){
        currentDay= HoyahCalendar.mDay;     
    }else {
        currentDay = this.mDay;
    }
    //String[][] a = new String[6][7];
    for (i=0;i<week_no;i++)
        HoyahCalendar.a[i/7][i%7] = "";

    for(i=week_no; i<week_no + month_days; i++){
        s = i - week_no + 1;
        HoyahCalendar.a[i/7][i%7] = String.valueOf(s);
        if (s == currentDay && HoyahCalendar.currentIndex == -1){
            HoyahCalendar.currentIndex = i/7;
        }
    } 
    for (i=0; i<7;i++){
        if (HoyahCalendar.a[HoyahCalendar.currentIndex][i] == null){
            HoyahCalendar.a[0][i] = "";
        }else{
            HoyahCalendar.a[0][i] =    
  HoyahCalendar.a[HoyahCalendar.currentIndex][i];
        }

    }
    for(i=week_no+month_days; i<42; i++)


        HoyahCalendar.a[i/7][i%7] = "";
}
   }
公共类HoyahCalendar扩展活动{
私人静态髓内;
公共静态int currentIndex=-1;
私有静态内存;
公共静态整数日;
公共静态字符串[][]a=新字符串[6][7];
私人文本查看日期(今日);;
ImageButton上个月;
下个月的ImageButton;
私人图像按钮上周;
私人图像按钮下个星期;
私有文本视图e00;
私有文本视图e01;
私有文本视图e02;
私有文本视图e03;
私有文本视图e04;
私有文本视图e05;
私有文本视图e06;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
date_today=(TextView)findViewById(R.id.date_today);
上个月=(ImageButton)findViewById(R.id.last\u month);
下个月=(ImageButton)findViewById(R.id.next\u month);
last_week=(ImageButton)findViewById(R.id.last_week);
下一周=(ImageButton)findViewById(R.id.next\u week);
e00=(TextView)findViewById(R.id.e00);
e01=(TextView)findViewById(R.id.e01);
e02=(TextView)findViewById(R.id.e02);
e03=(TextView)findViewById(R.id.e03);
e04=(TextView)findViewById(R.id.e04);
e05=(TextView)findViewById(R.id.e05);
e06=(TextView)findViewById(R.id.e06);
Calendar mCalendar=Calendar.getInstance();
mYear=mCalendar.get(日历年);
mMonth=mCalendar.get(日历月)+1;
mDay=mCalendar.get(日历、日期、月份);
///setListeners();
上个月.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
如果(mMonth==1){
mYear-=1;
mMonth=12;
新的展览日历(mYear,Ammonth);
显示屏幕();
}否则{
mMonth-=1;
新的展览日历(mYear,Ammonth);
显示屏幕();
}
}
});
next\u month.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
如果(mm==12){
髓鞘+=1;
mMonth=1;
新的展览日历(mYear,Ammonth);
显示屏幕();
}否则{
mMonth+=1;
新的展览日历(mYear,Ammonth);
显示屏幕();
}
}
});
上周.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
如果(mMonth==1){
mYear-=1;
mMonth=12;
新的展览日历(mYear、Amnoth、mDay,“最后一次”);
显示屏幕();
}否则{
//mMonth-=1;
新的展览日历(mYear、Amnoth、mDay,“最后一次”);
显示屏幕();
}
}
});
下周.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
如果(mm==12){
髓鞘+=1;
mMonth=1;
新的展示日历(mYear、Ammonth、mDay,“下一个”);
显示屏幕();
}否则{
if(HoyahCalendar.currentIndex==4){
HoyahCalendar.currentIndex=4;
//mMonth+=1;
}
新的展示日历(mYear、Ammonth、mDay,“下一个”);
显示屏幕();
}
}
});
新的展览日历(mYear,Ammonth);
显示屏幕();
}
屏幕上的公共无效显示(){
date_today.setText(mYear+年+月+);
e00.setText(“+a[0][0]);
e01.setText(“+a[0][1]);
e02.setText(“+a[0][2]);
e03.setText(“+a[0][3]);
e04.setText(“+a[0][4]);
e05.setText(“+a[0][5]);
e06.setText(“+a[0][6]);
}
}
公开课展示日历{
私人髓鞘内;
私人住宅;
私人国际日;
公共展览日历{
this.mYear=mYear;
this.month=month;
calculateMonthFirstday();
}
公共int getmDay(){
返回mDay;
}
公共void setmDay(int mDay){
this.mDay=mDay;
}
公共ShowCalendar(int mYear、int mMonth、int mDay、字符串时间){
this.mYear=mYear;
this.month=month;
如果(时间=“下一步”){
HoyahCalendar.currentIndex++;
if(HoyahCalendar.currentIndex==5){
HoyahCalendar.currentIndex--;
}
this.mDay=mDay+7;
}否则如果(时间=“最后一次”){
HoyahCalendar.currentIndex--;
if(HoyahCalendar.currentIndex=-1){
HoyahCalendar.currentIndex++;
}
this.mDay=mDay-7;
}
calculateMonthFirstday();
}
公共void calculateMonthFirstday(){
整月,第一天=0;
如果((mYear%4==0&&mYear%100!=0)| |(mYear%400==0))
月=1;
其他的
月份=0;
整数y,y12,c,c12,m,d;
y=mYear%100;
y12=(mYear-1)%100;//仅适用于一月和二月
c=mYear/100;
c12=(mYear-1)/100;
m=毫米;
d=1;
开关(毫米){
案例1:{第一天=y12+y12/4+c12/4-2*c12+26*(13+1)/10+d-1;休息;}
案例2:{第一天=y12+y12/4+c12/4-2*c12+26*(14+1)/10+d-1;休息;}
案例4:{第一天=y+y/4+c/4-2*c+26*(m+1)/10+d-1;休息;}
案例5:{第一天=y+y/4+c/4-2*c+26*(m+1)/10+d-1;休息;}
案例6:{第一天=y+y/4+c/4-2*c+26*(m+1)/10+d-1;休息;}
案例7:{第一