DatePickerFragment一个清理项目

时间:2013-04-09 08:05:38

标签: android android-dialogfragment android-datepicker

我的Android项目中有一个DatePickerFragment:

public class Uses extends FragmentActivity {


@Override
public void onCreate(Bundle savedInstanceState) {


  //code

}

public class parkingListHTTP extends AsyncTask<String, Void, String> {

     //code
    }

    @Override
    protected void onPostExecute(String result) {

         //code
}

public void returnUses(String date) {

    //code

}

public void selectDate(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getSupportFragmentManager(), "datePicker");
}

public 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 year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        // Do something with the date chosen by the user
        String dateText = context.getString(R.string.date_name);
        String[] strDays = new String[]{"Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sáb"};

        final Calendar c = Calendar.getInstance();

        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month-1);
        c.set(Calendar.DAY_OF_MONTH, day);

        int week = c.get(Calendar.DAY_OF_WEEK); 

        date.setText(dateText.replaceFirst("\\*",strDays[week - 1] + " " + day + "/" + (month+1)+"/"+year));
        returnUses(year+"-"+(month+1)+"-"+day);
    }
}

}

当我在项目中更改一些代码

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

返回错误:

 This fragment inner class should be static (com.usualbike.mandemo.Uses.DatePickerFragment)

但它解决了清理项目的问题。

如何避免此错误+清洁?

0 个答案:

没有答案