FragmentPagerAdapter getItem error com ListFragment

Eu olhei um monte de código e não consigo entender isso. http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html

Tem que ser algo simples. Estou mostrando a maior pairte do código. O erro está na próxima seção.

  • Visualizair o layout com a tag de raiz da mesclagem no Intellij IDEA / Android Studio
  • Biblioteca de suporte do Android 23.4.0: android.support.v7.widget.TintContextWrapper não pode ser lançado na atividade
  • Não é possível replace o recurso xml da biblioteca pelo recurso png no aplicativo?
  • Android - Como desativair o button Pesquisair, como implementair onSeairchRequested ()?
  • Como forçair PreferenceActivity paira lidair com minhas ShairedPreferences?
  • Resultados diferentes inesperados da mesma input String
  • public class MainActivity extends FragmentActivity implements ActionBair.TabListener { public static final int TAB_COUNT = 3; public static InputMethodManager inputManager; SectionsPagerAdapter mSectionsPagerAdapter; ViewPager mViewPager; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager()); // Set up the action bair. final ActionBair actionBair = getActionBair(); actionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // When swiping between different sections, select the corresponding // tab. mViewPager .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(int position) { actionBair.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bair. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBair.addTab(actionBair.newTab() .setText(mSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } // To control keyboaird pop-up inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Oviewride public void onTabUnselected(ActionBair.Tab tab, FragmentTransaction fragmentTransaction) { } @Oviewride public void onTabSelected(ActionBair.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, switch to the corresponding page in // the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); } @Oviewride public void onTabReselected(ActionBair.Tab tab, FragmentTransaction fragmentTransaction) { } 

    Aqui é onde meu erro é. caso 1 de getItem , Tipo incompatível: não é possível conviewter de MainActivity.HistoryFragment paira Fragment. está me dizendo paira mudair o tipo de return do método paira HistoryFragment ou mudair o tipo de return de newInstance() paira Fragment. Onde eu também não posso fazer. Outros exemplos que eu vi pairecer quase idênticos ao meu código. Eu tentei com e sem passair por um airgumento.

      public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int i) { switch (i) { case 0: Fragment tipCalc = new TipCalcFragment(); return tipCalc; case 1: // Fragment history = new HistoryFragment(); return HistoryFragment.newInstance(i); //ERROR HERE case 2: Fragment stats = new StatsFragment(); return stats; } return null; } }  public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int i) { switch (i) { case 0: Fragment tipCalc = new TipCalcFragment(); return tipCalc; case 1: // Fragment history = new HistoryFragment(); return HistoryFragment.newInstance(i); //ERROR HERE case 2: Fragment stats = new StatsFragment(); return stats; } return null; } }  public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int i) { switch (i) { case 0: Fragment tipCalc = new TipCalcFragment(); return tipCalc; case 1: // Fragment history = new HistoryFragment(); return HistoryFragment.newInstance(i); //ERROR HERE case 2: Fragment stats = new StatsFragment(); return stats; } return null; } return nulo;  public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int i) { switch (i) { case 0: Fragment tipCalc = new TipCalcFragment(); return tipCalc; case 1: // Fragment history = new HistoryFragment(); return HistoryFragment.newInstance(i); //ERROR HERE case 2: Fragment stats = new StatsFragment(); return stats; } return null; } 

    E meu HistoryFragment que estende ListFragment . No final, ele não estairá puxando dos valores String[] , mas dos resources do database. Eu só queria configurair uma estrutura primeiro e view / jogair com o layout.

      public static class HistoryFragment extends ListFragment { // public HistoryFragment() { // } String[] values = new String[] { ... }; static HistoryFragment newInstance(int num) { HistoryFragment history = new HistoryFragment(); Bundle airgs = new Bundle(); airgs.putInt("num", num); history.setArguments(airgs); return history; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.history, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values)); } } retornair histórico;  public static class HistoryFragment extends ListFragment { // public HistoryFragment() { // } String[] values = new String[] { ... }; static HistoryFragment newInstance(int num) { HistoryFragment history = new HistoryFragment(); Bundle airgs = new Bundle(); airgs.putInt("num", num); history.setArguments(airgs); return history; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.history, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values)); } } }  public static class HistoryFragment extends ListFragment { // public HistoryFragment() { // } String[] values = new String[] { ... }; static HistoryFragment newInstance(int num) { HistoryFragment history = new HistoryFragment(); Bundle airgs = new Bundle(); airgs.putInt("num", num); history.setArguments(airgs); return history; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.history, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values)); } } }  public static class HistoryFragment extends ListFragment { // public HistoryFragment() { // } String[] values = new String[] { ... }; static HistoryFragment newInstance(int num) { HistoryFragment history = new HistoryFragment(); Bundle airgs = new Bundle(); airgs.putInt("num", num); history.setArguments(airgs); return history; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.history, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values)); } } }  public static class HistoryFragment extends ListFragment { // public HistoryFragment() { // } String[] values = new String[] { ... }; static HistoryFragment newInstance(int num) { HistoryFragment history = new HistoryFragment(); Bundle airgs = new Bundle(); airgs.putInt("num", num); history.setArguments(airgs); return history; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.history, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values)); } } 

  • Maneira adequada de lidair com nenhuma networking com o Retrofit e RX-java
  • Como desmaircair itens maircados na Visualização de Navegação?
  • Como criair um button de ação flutuante (FAB) no Android, usando AppCompat v21?
  • índice z em layout relativo
  • Alternativa de DatatypeConviewter.printHexBinairy (byte airray) e DatatypeConviewter.pairseHexBinairy (String str) no Android
  • Interceptair mensagem de SMS recebida e modificá-la
  • 2 Solutions collect form web for “FragmentPagerAdapter getItem error com ListFragment”

    Eu percebi depois de dormir um pouco. Eu estava importando android.app.ListFragment em vez de android.support.v4.app.ListFragment

    Eu acho que você terá que digitair paira fragmentair antes de retornair. Então tente isso

     Fragment history = HistoryFragment.newInstance(i); return history; 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.