首先,为您的Fragment布局设置一个ID,例如:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:id="@+id/cameraFragment"**
tools:context=".CameraFragment">
并使用该ID将视图替换为另一个fragment.java文件。例如
ivGallary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UploadDoc uploadDoc= new UploadDoc();
(getActivity()).getSupportFragmentManager().beginTransaction()
.replace(**R.id.cameraFragment**, uploadDoc, "findThisFragment")
.addToBackStack(null)
.commit();
}
});
public class MyHostActivity extends AppCompatActivity implements MyFragmentOne.OnFragmentInteractionListener {
另外,检查您的主机活动是否具有下一个覆盖功能:`@Override public void onFragmentInteraction(Uri uri){}`希望这有帮助...