0
have in Mainactivity 3(three) Fragments (Homefragment, Channelfragment and Searchfragment), with change made through tabs with click only. Inside the Homefragment I have 2 (two) more Fragments (Videosfragment and Playlistfragment), this with change in click and tbm with a pager view.
It worked, but a problem arose after I added these last two Ragments. Because when I go to the Searchfragment screen, it’s cool, but when I go back to the start screen, the Homefragment, this appears tabs, but it turns all white, the content of Videofragment and Playlistfragment turns all white.
I get to see the logs, making requests, but simply does not appear the content.
I have tried to re-create on onCreate, etc without success.
Follows the methods for better understanding (Mainactivity):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
if(savedInstanceState != null) {
tabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
}
}
public void init() {
initializeTabHost();
initializeViewPager();
hideShowKeyboards(false);
}
private void initializeViewPager() {
List<Fragment> fragments = new ArrayList<>();
HomeFragment homeFragment = new HomeFragment();
fragments.add(homeFragment);
ChannelsListFragment channelsListFragment = new ChannelsListFragment();
fragments.add(channelsListFragment);
SearchFragment searchFragment = new SearchFragment() {
fragments.add(searchFragment);
FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
viewPagerCustom = (ViewPagerCustom) super.findViewById(R.id.main_viewPagerCustom);
viewPagerCustom.setAdapter(fragmentAdapter);
viewPagerCustom.addOnPageChangeListener(new PagerChangerListener());
}
public void initializeTabHost() {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
icHome = new ImageView(this);
icHome.setImageResource(R.mipmap.ic_home_clicked);
icChannel = new ImageView(this);
icChannel.setImageResource(R.mipmap.ic_channel);
icSearch = new ImageView(this);
icSearch.setImageResource(R.mipmap.ic_search);
addTab(this, this.tabHost, this.tabHost.newTabSpec("Tab 1").setIndicator(icHome));
addTab(this, this.tabHost, this.tabHost.newTabSpec("Tab 2").setIndicator(icChannel));
addTab(this, this.tabHost, this.tabHost.newTabSpec("Tab 3").setIndicator(icSearch));
tabHost.setOnTabChangedListener(new TabHostChangeListener());
}
Methods of Homefragment:
public HomeFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(container == null)
return null;
rootView = inflater.inflate(R.layout.fragment_home, container, false);
init();
Log.i("Ciclo", "onCreateView() sendo chamado HomeFragment");
return rootView;
}
private void init() {
initTabHost();
initializeVariables();
initializeViewPager();
}
private void initTabHost() {
fragmentTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
fragmentTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab 1").setIndicator("VÍDEOS"),
VideosFragment.class, null);
fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab 2").setIndicator("PLAYLISTS"),
PlaylistFragment.class, null);
fragmentTabHost.setOnTabChangedListener(new OnTabChangeListener());
fragmentTabHost.getTabWidget().setBackgroundResource(R.color.icomptv_blue);
//fillColor();
fillColorLine();
//Personaliza texto tabHost
for (int i = 0; i < fragmentTabHost.getTabWidget().getChildCount(); i++) {
TextView tv = (TextView) fragmentTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.parseColor("#FFFFFF"));
tv.setTextSize(15);
}
}
private void initializeViewPager() {
List<Fragment> fragments = new ArrayList<>();
VideosFragment videosFragment = new VideosFragment();
fragments.add(videosFragment);
PlaylistFragment playlistFragment = new PlaylistFragment();
fragments.add(playlistFragment);
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getFragmentManager(), fragments);
viewPager = (ViewPager) rootView.findViewById(R.id.main_viewPager);
viewPager.setAdapter(viewPagerAdapter);
viewPager.addOnPageChangeListener(new PagerChangerListener());
}
Oncreate from Videofragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null)
return null;
Log.i("Ciclo", "onCreateView() do VideoFragment");
view = inflater.inflate(R.layout.fragment_videos, container, false);
initMethods();
return view;
}
Good guys, who can tell me why this mistake? and propose a solution thank you
the setOffsScreenPageLimit() method works when I set the parameter to 3. but stop the search content appearing
– Berg Ferreira
Please enter your Adapter code. E substitua essa linha: FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments); 
por : FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager() , fragments);
– Caique Oliveira
Guy just changed that line that spoke and worked :D Obg, can you explain to me the difference between them ??
– Berg Ferreira
http://developer.android.com/intl/pt-br/about/versions/android-4.2.html#NestedFragments
– Caique Oliveira