gpt4 book ai didi

android - 隐藏安卓 fragment

转载 作者:行者123 更新时间:2023-11-29 02:37:46 26 4
gpt4 key购买 nike

使用 Android Framgent,我有三个 fragment 布局,我想根据标志隐藏 fragment 。当第一个 fragment 可见时,我想禁用第二个 fragment 我成功地能够隐藏选项卡布局的选项卡标题但无法删除页面。如何实现它。?我已经搜索了很多但没有找到我接受的。

public class Sample extends AppCompatActivity implements Commands.FragmentDataListener_Commands_epg{
Bundle dataBundle;
TabLayout tabLayout;
String flag;
private Sample.SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details_customer);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Intent intent=getIntent();
flag = intent.getStringExtra("flag");

mSectionsPagerAdapter = new Sample.SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
if(flag.equals("1")) {
tabLayout.removeTabAt(0);

}
else if(flag.equals("2"))
{
tabLayout.removeTabAt(1);
}

client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

}


@Override
public void onFragmentDataUpdated(Bundle dataBundle)
{
this.dataBundle=dataBundle;
}

@Override
public void onStart() {
super.onStart();

client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}

@Override
public void onStop() {
super.onStop();

AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
//first page
case 1:
//second page
}
return null;
}

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

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

提前谢谢你。

最佳答案

既然你在 Intent 中得到了标志,你就不需要 tabLayout。只是 init 和你 View 的 fragment 。一些代码如下:

Fragment fragmentInput = new  FragmentAddVehicle();
FragmentManager getSupportFragmentManager.beginTransaction().add(R.id.ll_root_container, fragmentInput).commit();

关于android - 隐藏安卓 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46032948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com