我在窗口管理器中添加了一个膨胀的布局。
void createFloatView()
{
final WindowManager wm = (WindowManager) this.getApplication().getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
_myView = (RelativeLayout) this.getLayoutInflater().inflate(R.layout.popup, null);
wm.addView(_myView, params);
}
这个布局包含一个我想要放入内容的FrameLayout,但是fragmentManager似乎找不到布局中存在的视图id(R.id.container)(R.layout.popup)。 / p>
void replaceFragment()
{
FragmentManager supportFragmentManager = getSupportFragmentManager();
supportFragmentManager.beginTransaction().replace(R.id.container, customFragment).commit();
}
它表示'没有找到id的视图'指向R.id.container
这是弹出式布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
我发现其他解决方案说我应该使用getChildFragmentManager()但我似乎无法弄清楚放在哪里,因为它说我不能把它放在静态上下文中?
那么我怎样才能让片段管理器访问这个id?