在静态类中使用非静态Spinner

时间:2014-10-08 19:20:38

标签: android static non-static

我正在努力做到这一点:

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

    public void onDateSet(DatePicker view, int year1, int month1, int day1) {
        firstdate = day1 + "/" + month1 + "/" + year1;
        addapter.add(firstdate);
        Spinner.setSelection(1);
    }
    

    任何人都可以帮助我吗? 提前致谢! 菲利普

1 个答案:

答案 0 :(得分:0)

全班:

 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;
           }

       }