2014-10-12 5 views
2

내가 이것을 만들려고 노력하고 있어요 : DatePickerDialog 사용자에 정적 클래스에서 비 정적 변수를 기입 (회 전자)

  • 날짜

    문제 스피너

  • 로 작성하는 날짜를 설정
    1. OnDateSet 메서드를 포함하는 DatePickerFragment 클래스가 정적이며 회 전자가 정적이 아닙니다. OnDateSet 방법에서 내가 어댑터 항목 호출 방법 Spinner.setSelection을 추가해야합니다 (INT I)

      public static class DatePickerFragment extends DialogFragment 
                implements DatePickerDialog.OnDateSetListener { 
      
            @Override 
            public Dialog onCreateDialog(Bundle savedInstanceState) { 
             // Use the current date as the default date in the picker 
             final Calendar c = Calendar.getInstance(); 
             int year1 = c.get(Calendar.YEAR)-25; 
             int month1 = 0; 
             int day1 = 1; 
      
      
             // Create a new instance of DatePickerDialog and return it 
             return new DatePickerDialog(getActivity(), this, year1, month1, day1); 
            } 
      
            public void onDateSet(DatePicker view, int year1, int month1, int day1) { 
             firstdate = day1 + "/" + month1 + "/" + year1; 
            } 
      
           } 
      

      오류이 줄에 있습니다

      firstdate = day1 + "/" + month1 + "/" + year1; 
      

      아무도 나를 도와 드릴까요?

      미리 감사드립니다.

    +1

    firstdate처럼 호출 할 수 있습니다 onDissmiss 예는 클래스 외부에 – Blackbelt

    +0

    을 선언되지 않았습니다 – Filip

    답변

    0

    조각 내에서도 선언 할 수 있으며 값을 반환하는 getter가 있습니다.

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

    및 활동에서

    , 당신은 mDialogInstance.getFirstDate();