Reputation: 15
Im trying to get the user to select a date when the click on a button and it shows 3 scroll wheels to choose day, month and year it will then set whatever the user selected to the text view, at the moment when i click the button nothing is happening just empty clicks any help would be appreciated. I will insert the code below. I am recieving an error on this line of code.
fragment.show(getSupportFragmentManager(), "date");
Datepicker Code
public void datePicker(View view) {
DatePickerFragment fragment = new DatePickerFragment();
fragment.show(getSupportFragmentManager(), "date");
}
public void setDate(final Calendar calendar) {
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
((TextView) findViewById(R.id.dateSet)).setText(dateFormat.format(calendar.getTime()));
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar cal = new GregorianCalendar(year, month, dayOfMonth);
setDate(cal);
}
public static class DatePickerFragment extends DialogFragment {
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(),
(DatePickerDialog.OnDateSetListener)
getActivity(), year, month, day);
}
public void show(FragmentManager supportFragmentManager, String date) {
}
}
}
Button and TextView Code:
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dateSet"
android:layout_above="@+id/Category"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp" />
<Button
android:text="Pick Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/dateSet"
android:layout_alignLeft="@+id/incomeDate"
android:layout_alignStart="@+id/incomeDate"
android:layout_marginBottom="17dp"
android:onClick="datePicker"
android:id="@+id/picDate" />
error:
Error:(135, 17) error: no suitable method found for show(android.support.v4.app.FragmentManager,String)
method DialogFragment.show(android.app.FragmentManager,String) is not applicable
(argument mismatch; android.support.v4.app.FragmentManager cannot be converted to android.app.FragmentManager)
method DialogFragment.show(FragmentTransaction,String) is not applicable
(argument mismatch; android.support.v4.app.FragmentManager cannot be converted to FragmentTransaction)
Upvotes: 1
Views: 377
Reputation: 83527
The error is a little confusing, especially if you only pay attention to the class names and ignore their packages. The problem is that the Support Library uses identical class names as the native API. To fix the problem, double check the imports for classes which should use the support library. For example
import android.support.v4.app.DialogFragment
Most likely you have
import android.app.DialogFragment
which is a class from the Native API. Even though these two classes have the same name, they are two different types because they are in different packages.
Upvotes: 1