Error switching FragmentActivity ... "Incompatible types" or "FragmentTransaction cannot be applied"

I needed to downgrade my interface from 4.x to 2.3.x. The 4.x interface was developed using Fragments and worked. To lower it, I replaced them with FragmentActivties, switched everything to the necessary version of support for Android version v4. The problem is that the Fragment switch does not work.

Import:

import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;

The error code is ft.replace (..) , basically it says that I need a fragment, not a MealsFragment fragment.

   @Override
   public void onClick(DialogInterface dialog, int which) {

            MealsFragment newFragment = null;
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (which == 0) {
                Log.e("CLick", "CLICKED");
                newFragment = newMealsFragment();
                MealsFragment.meals = 1;

            } else if (which == 1) {
                changeFragment1 = new MeasurementFragment();
                MeasurementFragment.dia = 1;
            }

            ft.replace(R.id.fl_content_frame, newFragment);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.commit();
        }

    });

Error in AndroidStudio:

replace(int, android.support.v4.app.Fragment) in FragmentTransition cannot be applied to (int, xx.xx.xx.ui.MealsFragment)

MealsFragment is a FragmentActivty

Logcat:

error: no suitable method found for replace(int,MealsFragment)
method FragmentTransaction.replace(int,Fragment,String) is not applicable
(actual and formal argument lists differ in length)
method FragmentTransaction.replace(int,Fragment) is not applicable
(actual argument MealsFragment cannot be converted to Fragment by method invocation conversion)

If I changed newFragment to

android.support.v4.app.Fragment newFragment = null;

A new error of incompatible types occurs . I am switching between these two errors, but I cannot get a solution.

+4
2

import android.support.v4.app.Fragment

MealsFragment. , FragmentActivity,

+11

import android.support.v4.app.Fragment;

in MealsFragment extends Fragment,

+4

Source: https://habr.com/ru/post/1530228/


All Articles