Answer the question
In order to leave comments, you need to log in
How to fix error with "androidx.fragment.app.Fragment"?
How to fix "androidx.fragment.app.Fragment cannot be converted to android.app.Fragment" error?
Due to my level of knowledge of Android studio, I do not understand how to solve this problem.
Please help.
package com.example.fragmentsrustamseipyshev;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.annotation.SuppressLint;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@SuppressLint("NonConstantResourceId")
public void Change (View view){
Fragment fragment = null;
switch (view.getId()){
case R.id.button:
fragment = new Fragment1();
break;
case R.id.button1:
fragment = new Fragment2();
break;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fr_place, fragment);
ft.commit();
}
}
Answer the question
In order to leave comments, you need to log in
migrate to x to the end
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
Namely, for the fragment from the question
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question