gpt4 book ai didi

java - FragmentTransaction 无法转换为 Fragment Manager

转载 作者:行者123 更新时间:2023-11-30 01:51:49 37 4
gpt4 key购买 nike

有人知道怎么解决吗?如何将 fragmentTransaction 转换为 fragment 管理器?我在 Information Activity 中有一个 datePicker,在 WorkDetails Activity 中有一个 TimePicker。如果有任何建议,我将不胜感激。谢谢

Information.java

   dialog = new DateDialog();
public void onClick(View arg0) {
FragmentTransaction ft =getActivity().getSupportFragmentManager().beginTransaction();
dialog.show(ft, "DatePicker");

}
public static class DateDialog extends android.app.DialogFragment implements DatePickerDialog.OnDateSetListener {
// EditText txtdate;
Tab t;


public DateDialog() {

}


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 void onDateSet(DatePicker view, int year, int month, int day) {
String date = day + "-" + (month + 1) + "-" + year;
txtDate.setText(date);
date1 = txtDate.getText().toString();
return;
//t.add(date);


}
}

WorkDetails.java

 if (id == R.id.editTextTI2) {
tp.setFlag(TimePick.FLAG_START_DATE1);
FragmentTransaction ft =getActivity().getSupportFragmentManager().beginTransaction();
tp.show(ft, "TimePicker");
}

错误

Error:(51, 15) error: 

no suitable method found for show(android.support.v4.app.FragmentTransaction,String)
method DialogFragment.show(FragmentManager,String) is not applicable
(argument mismatch; android.support.v4.app.FragmentTransaction cannot be converted to FragmentManager)
method DialogFragment.show(android.app.FragmentTransaction,String) is not applicable
(argument mismatch; android.support.v4.app.FragmentTransaction cannot be converted to android.app.FragmentTransaction)

最佳答案

Information.java

使用 public static class DateDialog extends android.support.v4.app.DialogFragment implements DatePickerDialog.OnDateSetListener 而不是 public static class DateDialog extends android.app.DialogFragment implementsDatePickerDialog .OnDateSetListener。

WorkDetails.java

public static class TimePick extends android.support.v4.app.DialogFragment implements TimePickerDialog.OnTimeSetListener 

关于java - FragmentTransaction 无法转换为 Fragment Manager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32925661/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com