【发布时间】:2016-11-03 18:52:40
【问题描述】:
我想在活动的自定义对话框中放置一个片段。
我收到此错误:
java.lang.IllegalArgumentException: No view found for id 0x7f0c007e (copyworld.rebootcw:id/container_schedule1) for fragment FragmentGiorno{418215c0 #0 id=0x7f0c007e}
这是我的代码:
layout.xml
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_below="@+id/spinner_dialog_schedulazione"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="@+id/container_schedule1">
</FrameLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Popup_schedule();
}
//******POPUP PER LA SCHEDULAZIONE******************
public void Popup_schedule() {
dialog_schedule=new Dialog(MainActivity.this);
dialog_schedule.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog_schedule.setContentView(R.layout.dialog_schedule);
dialog_schedule.setCancelable(false);
lp = new WindowManager.LayoutParams();
window = dialog_schedule.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog_schedule.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window = dialog_schedule.getWindow();
window.setAttributes(lp);
FragmentGiorno fragment = new FragmentGiorno();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.container_schedule1, fragment);
fragmentTransaction.commit();
dialog_schedule.show();
}
}
如何在扩展 Activity 的 MainActivity.java 中的自定义对话框中添加片段?
【问题讨论】:
-
我尚未对此进行测试,但想指出几个潜在的问题 -
onCreate()将内容视图设置为R.id.activity_main,但您的帖子提到了layout.xml。只需检查这实际上是您的 res / layout 文件夹中的activity_main.xml。其次,android:layout_below="@+id/spinner_dialog_schedulazione"不应在 @ 符号后包含 +,因为您所指的元素应该有自己的 ID(而不是尝试创建一个) -
您的
activity_main.xml是否包含ID 为container_schedule1的FrameLayout?? -
对不起,我的布局是activity_main.xml
-
container_schedule1 位于 dialog_custom.xml 中
标签: java android android-fragments android-studio fragment