yas*_*sin 1 android android-fragments
我有一个片段,它是另一个片段的父片段。我正在添加这样的片段子项:
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main, container, false);
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.add(R.id.list_container, new SwipeableFragment(), FRAGMENT_LIST_VIEW).commit();
        transaction.addToBackStack(FRAGMENT_LIST_VIEW);
 return view;
}
后来,我的父片段中有一个方法需要找到孩子。所以我这样做:
final Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_LIST_VIEW);
但总是返回空值。我究竟做错了什么?
小智 5
使用下面给出的代码更改此代码:
// Your Code:
final Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_LIST_VIEW);
// Replace with this:
final Fragment fragment = getChildFragmentManager().findFragmentByTag(FRAGMENT_LIST_VIEW);
希望它会起作用!
| 归档时间: | 
 | 
| 查看次数: | 1866 次 | 
| 最近记录: |