0
我通过主活动发送接口从片段5至3:片段到碎片接口错误(布局)
public void setF3Riddle(int x) {
Frag3 F3 = (Frag3) getSupportFragmentManager().findFragmentById(R.id.Frag3);
if (F3 != null) {
F3.getF3Riddle(x);
} else {
Frag3 frag = new Frag3();
Bundle args = new Bundle();
args.putInt("Value", x);
frag.setArguments(args);
getSupportFragmentManager().beginTransaction()
.replace(R.id.Frag3, frag)
.addToBackStack(null)
.commit();
frag.getF3Riddle(x);
}
}
但是,当我发送数据运行时它崩溃。当我将.replace(R.id.Frag3,Frag)
容器更改为另一个不会崩溃的碎片时,我注意到了这个问题。这里有什么问题?
片段3布局:
<FrameLayout 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/Frag3"
tools:context="com.redot.puzzle3.Frag3">
非常感谢您在这方面的时间和帮助。
3已经存在,我已经做了同样的事情片段4和它的工作。我认为这个问题是与布局,因为当我Frag4替换片段ID'R.id.Frag3'和它不崩溃,它只是代替我想它来代替frament 3片段4,但由于某种原因崩溃 – amirsoltani