我的一个片段中存在一个包含TabLayout的问题。 TabLayout和每个选项卡内的数据工作正常,但我仍然遇到moveToState
错误(当我在第一个和最后一个之间切换时,这个错误不会出现,只有从第一个到中间,最后一个到中间)。我的应用程序仍然可以正常处理错误但我更愿意摆脱它以避免任何可能的未来并发症。
logcat的
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
如果需要更多信息,请通知我。
答案 0 :(得分:1)
这只是一条信息日志消息...... 有an issue about it.
项目成员#14 ad ... @ android.com 不,这没关系,额外的日志将在未来的版本中消失。
好奇的是,FragmentManager.moveToState现在更新新的片段状态,而不是在所有状态更改阶段完成后的最后。这解决了在父片段的一个生命周期回调中使用子片段管理器和executePendingTransactions的几个有趣的错误。
我们正在提供一个片段的状态转换之一是一个无操作,没有让状态更新内联,你看到的日志宣布我们在最后完成它,确切地说正如我们在23.2之前所做的那样。
抱歉额外的对数噪音:)