0

I'm trying to create a dialog fragment (actually a time picker dialog) in an android project that has a minimum SDK of android 8, but i get an error stating that API level 11 is required. Android documentation states that "Although DialogFragment was first added to the platform in Android 3.0 (API level 11), if your app supports versions of Android older than 3.0—even as low as Android 1.6—you can use the DialogFragment class that's available in the support library for backward compatibility".

Here's my code if this is relevant. As you can see, i've imported the class that's in the support library:

package com.example.fitnessalarm;

import java.util.Calendar;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;

public class MyDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        // Create a new instance of TimePickerDialog and return it
        return new TimePickerDialog(getActivity(), this, hour, minute,
                DateFormat.is24HourFormat(getActivity()));
    }

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        // Do something with the time chosen by the user
    }
}
syb0rg
  • 8,057
  • 9
  • 41
  • 81
stensootla
  • 13,945
  • 9
  • 45
  • 68

1 Answers1

0

The snippet you provide is correct also for pre Android 3.0. If you are sure you are not using Api that was not compatible with the minSdk version, you can add a @SuppressLint('NewApi') annotation to fix your issue

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I got frustrated yesterday with the error and decided to call it a day. Today, i opened eclipse and the error was gone. I guess the eclipse just didn't recognize my imported class or something (even though i refreshed my project). But thank you nevertheless for the feedback. – stensootla Apr 29 '13 at 13:26