Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android &引用;指定的子级已具有父级。必须对子对象&x27;调用removeView();“父母第一”;当替换片段时_Android_Android Fragments_Replace_Android Nested Fragment_Fragmentmanager - Fatal编程技术网

Android &引用;指定的子级已具有父级。必须对子对象&x27;调用removeView();“父母第一”;当替换片段时

Android &引用;指定的子级已具有父级。必须对子对象&x27;调用removeView();“父母第一”;当替换片段时,android,android-fragments,replace,android-nested-fragment,fragmentmanager,Android,Android Fragments,Replace,Android Nested Fragment,Fragmentmanager,首先我想解释一下我的布局。它是“选项卡中的选项卡列表”,这意味着列表视图由一个选项卡控制,而选项卡列表由另一个选项卡控制。希望你能理解我的意思 我的两个选项卡小部件: (底部选项卡:主控制面板) (列表选项卡:仅控制列表视图) ListPost类中的代码(太长,所以我删掉了关键部分) 错误(显示为title)发生在我单击列表视图元素时,这意味着替换片段。我做错了什么???哦……我只是在postdail课上犯了个愚蠢的错误 在onCreateView中,我错误地键入了充气部件,现在我将其更正为充气

首先我想解释一下我的布局。它是“选项卡中的选项卡列表”,这意味着列表视图由一个选项卡控制,而选项卡列表由另一个选项卡控制。希望你能理解我的意思

我的两个选项卡小部件:

(底部选项卡:主控制面板)

(列表选项卡:仅控制列表视图)

ListPost
类中的代码(太长,所以我删掉了关键部分)


错误(显示为title)发生在我单击列表视图元素时,这意味着替换片段。我做错了什么???

哦……我只是在
postdail
课上犯了个愚蠢的错误

onCreateView
中,我错误地键入了充气部件,现在我将其更正为
充气(R.layout.list\u detail,container,false)

现在可以运行了,谢谢兄弟们帮助我

public class BottomTabWidget extends FragmentActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bottom_tab);

        FragmentTabHost tabHost = (FragmentTabHost)findViewById(R.id.bottom_tab_host);

        tabHost.setup(this, getSupportFragmentManager(), R.id.bottom_tab_content);

        View exploreView = LayoutInflater.from(this).inflate(R.layout.explore, null);         
        View browseView = LayoutInflater.from(this).inflate(R.layout.browse, null);
        View profileView = LayoutInflater.from(this).inflate(R.layout.profile, null);
        View cartView = LayoutInflater.from(this).inflate(R.layout.cart, null);

        tabHost.addTab(tabHost.newTabSpec("explore").setIndicator(exploreView), ListTabWidget.class, null);        
        tabHost.addTab(tabHost.newTabSpec("browse").setIndicator(browseView), SearchList.class, null);
        tabHost.addTab(tabHost.newTabSpec("profile").setIndicator(profileView), SearchList.class, null);
        tabHost.addTab(tabHost.newTabSpec("cart").setIndicator(cartView), SearchList.class, null);
    }
}
public class ListTabWidget extends Fragment{

    //for extending Fragment
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedIntanceState){
        //View view = inflater.inflate(R.layout.list_tab, container);

        //FragmentTabHost tabHost = (FragmentTabHost)view.findViewById(R.id.list_tab_host);
        FragmentTabHost tabHost = new FragmentTabHost(getActivity());

        tabHost.setup(getActivity(), getChildFragmentManager(), R.id.listtabcontent);
        View tabView = setTab(inflater, "  New Items  ");
        tabHost.addTab(tabHost.newTabSpec("all_post").setIndicator(tabView), ListPost.class, null);

        return tabHost;
    }

    private View setTab(LayoutInflater inflater, String text){
        View tabView = inflater.inflate(R.layout.list_tab_text, null);
        TextView textView = (TextView)tabView.findViewById(R.id.textView);
        textView.setText(text);
        return tabView;
    }
}
listView = (ListView)this.getView().findViewById(android.R.id.list);

        list  = new CustomAdapter(this.getActivity() ,android.R.layout.simple_selectable_list_item, productArray);
        listView.setAdapter(list);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                Product item = (Product) parent.getItemAtPosition(position); 

                Bundle args = new Bundle();             
                args.putString("pid", item.getData(WPTemplateDB.PRODUCT_ID)+"");

                //switchFragment(args);
                new FragmentProcess().switchFragment(getActivity(), R.id.bottom_tab_content, new PostDetail(), args);
            }           
        });
public class FragmentProcess {

    public void switchFragment(FragmentActivity activity, int element, Fragment replaceFragment, Bundle args){
        replaceFragment.setArguments(args);
        FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();

        transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
        transaction.replace(element, replaceFragment);
        transaction.addToBackStack(null);

        transaction.commit();
    }
}