Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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_Variables_Static_Non Static - Fatal编程技术网

Android 在静态类中填充非静态变量(微调器)

Android 在静态类中填充非静态变量(微调器),android,variables,static,non-static,Android,Variables,Static,Non Static,我试图做到这一点: 在DatePickerDialog中,用户设置日期 日期将在微调器中写入 问题在于,包含OnDateSet方法的DatePickerFragment类是静态的,而微调器是非静态的。在OnDateSet方法中,我需要将项添加到适配器并调用方法Spinner.setSelection(inti) 错误在这一行: firstdate = day1 + "/" + month1 + "/" + year1; 有人能帮我吗 提前感谢。您也可以在片段中声明它,并有一个返回其值的gett

我试图做到这一点:

  • 在DatePickerDialog中,用户设置日期
  • 日期将在微调器中写入
  • 问题在于,包含OnDateSet方法的DatePickerFragment类是静态的,而微调器是非静态的。在OnDateSet方法中,我需要将项添加到适配器并调用方法Spinner.setSelection(inti)

    错误在这一行:

    firstdate = day1 + "/" + month1 + "/" + year1;
    
    有人能帮我吗


    提前感谢。

    您也可以在片段中声明它,并有一个返回其值的getter

    public static class DatePickerFragment extends DialogFragment
                            implements DatePickerDialog.OnDateSetListener {
    
     private int firstdate;
    
     // .. other code
    
     public int getFirstDate() {
        return firstdate;
     }
    
    }
    

    从活动中,可以像
    mDialogInstance.getFirstDate()那样调用它

    未声明firstdate是的,它在类之外
    public static class DatePickerFragment extends DialogFragment
                            implements DatePickerDialog.OnDateSetListener {
    
     private int firstdate;
    
     // .. other code
    
     public int getFirstDate() {
        return firstdate;
     }
    
    }