【问题标题】:FragmentTransaction cannot be converted to Fragment ManagerFragmentTransaction 无法转换为 Fragment Manager
【发布时间】:2015-10-03 17:56:18
【问题描述】:

有谁知道如何解决这个问题?如何转换fragmentTransaction to fragment manager?我在Information 活动中有一个datePicker,在WorkDetails 活动中有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)

【问题讨论】:

    标签: java android android-fragments datepicker timepicker


    【解决方案1】:

    添加import android.support.v4.app.FragmentTransaction;要么 import android.support.v4.app.*

    【讨论】:

      【解决方案2】:

      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 
      

      【讨论】:

        猜你喜欢
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-29
        相关资源
        最近更新 更多