我想使用ActionBar/Viewpager來爲片段提供標籤支持。但是,與每個片段相關的片段,我希望它是一個ListFragment。下面是我從有效的導航例如ListFragment with viewPager
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
[..]
public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {
public AppSectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
Fragment fragment0 = new DummySectionFragment();
Bundle args0 = new Bundle();
args0.putString(DummySectionFragment.TAB_NAME, "Public");
fragment0.setArguments(args0);
((ListFragment)fragment0).setEmptyText("EMPTY");
return fragment0;
得到了我的培訓相關的代碼示例[..]
public static class DummySectionFragment extends ListFragment {
public static final String TAB_NAME = "tab_name";
[..] 問題是,FragmentPagerAdapter.getItem期待一個片段。當我試圖訪問ListFragment的方法時,它崩潰了。請指教。感謝
類似的問題,解決了:請參閱答案 http://stackoverflow.com/questions/10255094/how-to-implements-a-listfragment-into-your-project-from-a-sample – Gautam