0
我使用以下方法來選擇我的活動....碎片內的碎片或ListActivity內的碎片?
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment;
switch (position) {
case 0:
fragment = new Fragment1();
break;
case 1:
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
default:
fragment = null;
break;
}
return fragment;
}
...空白和工作片段看起來像中顯示的片段....
public class Fragment2 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_dod, container, false);
// Do Stuff Here
return root;
}
@Override public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save some state!
}
}
如何過我SectionsPagerAdapter與類型不匹配錯誤:無法從Fragment2轉換使用下面這樣的ListFragment時,分片.....
public class Fragment2 extends ListFragment {
DemoAdapter adapter=null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
if (adapter==null) {
ArrayList<Integer> items=new ArrayList<Integer>();
for (int i=0;i<25;i++) { items.add(i); }
adapter=new DemoAdapter(getActivity(), items);
}
else {
adapter.startProgressAnimation();
}
setListAdapter(adapter);
}
}
我一直在尋找˚F或者一種解決這個問題的方法。難道有人建議採取這種方式嗎?如果可能的話,我會理解爲什麼,並且可以在未來避免這種解釋?
感謝
我不明白...爲什麼你有一個叫做'Fragment2'類延伸'Fragment',也有一個叫做'Fragment2'類延伸'ListFragment'? – Squonk
我發現這個問題(http://stackoverflow.com/questions/15321666/replace-listfragment-with-fragment-inside-viewpager-with-tabs)這似乎接近我所需要的。如果是,我會回覆一個答案。 –
............... –