私は4つの断片活性がタブバーの主な活動に付いています。同様に、下のリンクのよう frag 1
、frag 2
、frag 3
、frag 4
最初のフラグメントが空であれば、antotherフラグメント画面に動的に移動するには?
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
assert toolbar != null;
toolbar.setLogo(R.drawable.toplogo);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
if (tabLayout != null) {
tabLayout.addTab(tabLayout.newTab().setText("Videos"));
}
if (tabLayout != null) {
tabLayout.addTab(tabLayout.newTab().setText("Music"));
}
if (tabLayout != null) {
tabLayout.addTab(tabLayout.newTab().setText("MindMaps"));
}
if (tabLayout != null) {
tabLayout.addTab(tabLayout.newTab().setText("Quiz"));
}
/* if (tabLayout != null) {
tabLayout.addTab(tabLayout.newTab().setText("Discussion"));
}*/
if (tabLayout != null) {
tabLayout.setTabTextColors(parseColor("#ffffff"), parseColor("#f1bf8f"));
}
mViewPager = (ViewPager) findViewById(R.id.container);
if (mViewPager != null) {
mViewPager.setAdapter(mSectionsPagerAdapter);
}
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
if (tabLayout != null) {
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
}
@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) {
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new Videos();
case 1:
return new Music();
case 2:
return new MindMaps();
case 3:
return new Quiz();
/* case 4:
return new Discussion();*/
}
return null;
}
@Override
public int getCount() {
return 4;
}
。
画像:
それぞれのリストビューが含まれています。 これらのフラグメントはAPIからデータを取得しており、リストビューに表示されます。 フラグ1でlistviewが空の場合、空でないリストを持つ別のフラグメントに動的に移動する方法。
明確化が必要な場合は教えてください。
あなたは@AkshayBhat –