Olá programadores,
Sou iniciante e gostaria se possível na ajuda para resolver esse erro de compilação ao instanciar um FragmentTransation, desde já agradeço a ajuda:
package com.example.backstack;
import androidx.appcompat.app.AppCompatActivity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.app.Fragment;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment_1 f1 = new Fragment_1();
Fragment_2 f2 = new Fragment_2();
Fragment_3 f3 = new Fragment_3();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.lay_top, f1, "f1");
ft.add(R.id.lay_middle, f2, "f2");
ft.add(R.id.lay_bottom, f3, "f3");
ft.commit();
}
}
Esse é o código de uma das fragments:
<?xml version="1.0" encoding="utf-8"?><TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@android:color/holo_green_light"
android:text="Fragment 1"
android:gravity="center"/>
E aqui o da activityMain:
<?xml version="1.0" encoding="utf-8"?><FrameLayout
android:id="@+id/lay_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout
android:id="@+id/lay_middle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout
android:id="@+id/lay_bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>