我的一个包含 TabLayout 的 fragment 出现问题。 TabLayout 和每个选项卡内的数据工作正常,但我仍然收到 moveToState
错误(当我在第一个和最后一个之间切换时,不会出现此错误,只会从第一个到中间,最后一个到中间).我的应用程序仍然可以很好地处理错误,但我更愿意摆脱它以避免将来可能出现的任何并发症。
洛格卡特
04-23 00:08:04.064 1598-1598/org.ramferno.scoutapplication.ramfernoscout W/FragmentManager: moveToState: Fragment state for TeamInfoTabOneFragment{1788a4f #9 id=0x7f0c00ca} not updated inline; expected state 3 found 2
04-23 00:12:56.007 1598-1598/org.ramferno.scoutapplication.ramfernoscout W/FragmentManager: moveToState: Fragment state for TeamInfoTabThreeFragment{29125dc #7 id=0x7f0c00ca} not updated inline; expected state 3 found 2
TeamInfoFragment.java(带tabLayout)
package org.ramferno.scoutapplication.ramfernoscout.fragments;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.ramferno.scoutapplication.ramfernoscout.adapters.InfoPagerAdapter;
import org.ramferno.scoutapplication.ramfernoscout.R;
/**
* A simple {@link Fragment} subclass.
*/
public class TeamInfoFragment extends Fragment {
TabLayout tabLayout;
ViewPager viewPager;
InfoPagerAdapter infoPagerAdapter;
public TeamInfoFragment() {
// Required empty public constructor
} //End of TeamInfoFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_team_info, container, false);
//Initializes variables
tabLayout = (TabLayout) view.findViewById(R.id.infoTabLayout);
viewPager = (ViewPager) view.findViewById(R.id.infoPager);
//Adds tabs to viewPager
infoPagerAdapter = new InfoPagerAdapter(getFragmentManager());
infoPagerAdapter.addFragments(new TeamInfoTabOneFragment(), "Team Info");
infoPagerAdapter.addFragments(new TeamInfoTabTwoFragment(), "Achievements");
infoPagerAdapter.addFragments(new TeamInfoTabThreeFragment(), "Past Tournaments");
//Sets adapter for viewPager then sets the same view pager for tabLayout
viewPager.setAdapter(infoPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
return view;
} //End of onCreateView
} //End of class
InfoPagerAdapter.java
package org.ramferno.scoutapplication.ramfernoscout.adapters;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
public class InfoPagerAdapter extends FragmentStatePagerAdapter {
ArrayList<Fragment> fragments = new ArrayList<>();
ArrayList<String> tabTitles = new ArrayList<>();
public void addFragments(Fragment fragments, String titles) {
this.fragments.add(fragments);
this.tabTitles.add(titles);
} //End of addFragments
public InfoPagerAdapter(FragmentManager fm) {
super(fm);
} //End of InfoPagerAdapter
@Override
public Fragment getItem(int position) {
return fragments.get(position);
} //End of getItem
@Override
public int getCount() {
return fragments.size();
} //Edn of getCount
public CharSequence getPageTitle(int position) {
return tabTitles.get(position);
} //End of getPageTitle
} //End of class
如果需要更多信息,请通知我。
最佳答案
这只是一条信息性日志消息... 有 an issue about it.
Project Member #14 ad...@android.com Nope, it doesn't matter and the extra log will be gone in a future release.
For the curious, FragmentManager.moveToState now updates the new fragment state as it goes rather than at the end after all of the state change phases have completed. This fixed several interesting bugs around using the child fragment manager and executePendingTransactions from within one of the parent fragment's lifecycle callbacks.
One of the state transitions as we're bringing a fragment up is a no-op that wasn't getting the state updated inline, and the log you're seeing is announcing that we did it at the end instead, exactly as we would have prior to 23.2.
Sorry for the extra log noise :)
关于java - Android - fragment 中 TabLayout 的中间选项卡错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36806565/