我的SectionsPageAdapter
看起来像这样:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
private List<PopularFragment> fragments;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
fragments = new ArrayList<MainActivity.PopularFragment>();
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// below).
PopularFragment f = PopularFragment.newInstance(position);
fragments.add(f);
return f;
}
public List<PopularFragment> getFragments() {
return fragments;
}
(...)
在Activity
onCreate
我致电:
new DownloadTask(new Handler()) {
private boolean result;
@Override
void doOnUiThread() {
if (!result) {
MainActivity.noConnection(MainActivity.this);
return;
}
for (PopularFragment f : mSectionsPagerAdapter.getFragments())
f.load();
loaded = true;
}
@Override
void doInBackground() {
result = popular.download();
}
}.execute();
在方向更改后,永远不会调用load()
。这是为什么?
以下是整个MainActivity.java
:http://pastebin.com/0pEDdjHS
答案 0 :(得分:1)
可能只是因为在适配器中的getItem之前调用了doOnUiThread。 检查mSectionsPagerAdapter.getFragments()它可能是空的