基本构造是popupwindows中有两个构造不同的fragment,只显示一个,用按键来回切换。
按照通常的FragmentTransaction.replace来作切换的话,会报错java.lang.IllegalArgumentException: No view found for id 0x1020002 (android:id/next_fragment) for fragment。
原因估计是因为R.id.next_fragment,是写在pupupwindows的layout文件里,在Activity自己的layout里边找不到。
那么除了手动隐藏/显示layout之外,有什么办法能够在popupwindow里直接切换fragment吗?
先谢过各位了。
source如下:
Button btnNext = (Button) v.findViewById(R.id.button_update);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 切换弗拉个闷特
FragmentManager manager = mActivity.getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.next_fragment, new NextFragment());
transaction.commit();
}
});
------解决思路----------------------
viewpager可以实现,原来用replace经常报错,already add
------解决思路----------------------
popupwindow并不能使用fragment,你可以使用ViewPager代替
------解决思路----------------------
自定义一个popupwindows吧,复写里面的方法就可以了
------解决思路----------------------
根据当前布局LinearLayout 接口getChildAt获取子组件,再对它进行操作。
报错原因可能是popupwindow父控件没有设置,看下popupwindow的创建接口