gabrjan gabrjan - 1 year ago 64
Android Question

The method 'getSupportFragmentManager()' is unsuported

So i'm trying to enable datepicker for android versions bellow 11. for that i'm using support library v4. I import all the thing necessary:


And i created a class:

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.os.Bundle;
import android.widget.EditText;
public class DatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {

public EditText textField;

public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
return new DatePickerDialog(getActivity(), this, year, month, day);

public EditText getTextField() {
return textField;

public void setTextField(EditText textField) {
this.textField = textField;

public void onDateSet(DatePicker view, int year, int month, int day) {

public void onDateSet(android.widget.DatePicker arg0, int arg1, int arg2,int arg3) {

So class compile ok. But the problem is when i try to use it. I have an onclick method for edittext that looks like that:

public void showDatePicker(View v) {
DialogFragment selectDate = (DialogFragment) new DatePicker();
EditText edit=(EditText)v;
((DatePicker) selectDate).setTextField(edit);, "datePicker");

however in last line i get the error:

The method getSupportFragmentManager() is undefined for the type MainActivity

Any ideas how to resolve that? btw i don't have imported anything like;

So that is not the case here :S

Answer Source

My guess is that your MainActivity is not extending FragmentActivity! In the SupportPackage an Activity must inherit from FragmentActivity to get Methods like getSupportedFragmentManager().


Since your Activity is inheriting from another class, you can try to implement the Behavior of one of these classes and kind of merge them. I.e here you'll find the code for FragmentActivity: FragmentActivity Source

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download