時候不要叫我有一個是這樣的手機上一個觀點:兒童片段的onCreateView()使用支持LIB V4 rev20
MainActivity
包含PaymentsFragment
,其中包含一個FragmentPagerAdapter
,又包含2 TransactionsListFragments
。
PaymentFragment
示例代碼:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRetainInstance(true);
mPaymentsPagerAdapter = new PaymentsPagerAdapter(getActivity(), getChildFragmentManager(), this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_payments, container, false);
assert view != null;
if (!isFirstRun)
mPaymentsPagerAdapter.setOnTransactionClickListener(this);
else
isFirstRun = false;
ViewPager viewPager = (ViewPager) view.findViewById(R.id.fragment_payments_viewpager);
viewPager.setAdapter(mPaymentsPagerAdapter);
PagerSlidingTabStrip pagerSlidingTabStrip = (PagerSlidingTabStrip) view.findViewById(R.id.fragment_payments_tabstrip);
pagerSlidingTabStrip.setViewPager(viewPager);
return view;
}
PaymentsPagerAdapter
示例代碼:
@Override
public Fragment getItem(int position)
{
switch (position)
{
case 0:
TransactionsListFragment recurringPaymentsListFragment = TransactionsListFragment.newRecurringPaymentsInstance();
recurringPaymentsListFragment.setOnTransactionClickListener(mPaymentsFragment);
return recurringPaymentsListFragment;
case 1:
TransactionsListFragment paymentsListFragment = TransactionsListFragment.newPaymentsInstance();
paymentsListFragment.setOnTransactionClickListener(mPaymentsFragment);
return paymentsListFragment;
}
return null;
}
內TransactionsListFragment
沒有什麼多的事情。此外,它的onCreate()和它的onCreateView()都沒有被調用,所以我認爲在PaymentsFragment
或PaymentsPagerAdapter
中有錯誤。
問題是,在升級到Support v4 lib rev20之前,所有代碼都完美無缺地工作。我降級到rev19,它再次工作。那麼,關於是什麼導致這種錯誤在20版中失敗了,還是它是一個錯誤?此外,如果有的話,解決方法是什麼?