Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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
DeveloperStudio中的Android:Fragment选项卡示例:如何删除第2节_Android_Tabs_Fragment - Fatal编程技术网

DeveloperStudio中的Android:Fragment选项卡示例:如何删除第2节

DeveloperStudio中的Android:Fragment选项卡示例:如何删除第2节,android,tabs,fragment,Android,Tabs,Fragment,如何删除Developer Studio生成的示例的第二部分 我尝试了很多东西,也开始尝试。。。承诺 我不能发布这个代码示例,因为发布系统不允许我粘贴完整的代码 我使用的是Developer Studio生成的片段选项卡示例 // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set u

如何删除Developer Studio生成的示例的第二部分

我尝试了很多东西,也开始尝试。。。承诺

我不能发布这个代码示例,因为发布系统不允许我粘贴完整的代码

我使用的是Developer Studio生成的片段选项卡示例

    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);



    FragmentManager fm = getSupportFragmentManager();
    android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();

mViewPager.removeView(mViewPager.getChildAt(1));

    ft.commit();
这不管用

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_SECTION_NUMBER = "section_number";

    public PlaceholderFragment() {
    }

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        TextView textView = (TextView) rootView.findViewById(R.id.section_label);
        textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
        return rootView;
    }
    }

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).
        return PlaceholderFragment.newInstance(position + 1);
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
        case 0:
            return "SECTION 1";
        case 1:
            return "SECTION 2";
        case 2:
            return "SECTION 3";
        }
        return null;
    }
    }
}

您是在使用示例来学习如何使用它,还是希望在实际项目中使用它?如果是这样的话,你能解释一下你想让这段代码做什么吗?它在我的应用程序中使用:我想取消标签(即片段),用户被取消选中。/*不工作/mviewpage.removeView(mviewpage.getChildAt(2));mSectionsPagerAdapter.notifyDataSetChanged();/不工作mSectionsPagerAdapter.startUpdate(findViewById(R.id.container));msectionspageradopter.destroyItem(findViewById(R.id.container),2,msectionspageradopter.getItem(2));mSectionsPagerAdapter.finishUpdate(findViewById(R.id.container));