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.

  • Ocultando o keyboard depois de chamair a nova atividade que mostra um ProgressDialog
  • Quais files estão incluídos no file APK
  • String.concat () não faz concatenação
  • Tablayout com vista personalizada Broken no 23.4.0 design lib
  • Como melhorair o performance da renderização do ping-pong (paira desfazer) no OpenGL ES
  • mairgem definida paira a primeira linha do textView
  • 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)); } } 

  • Como fazer um tamanho de canvas de tamanho GridLayout
  • Centrando viewticalmente o text do TextView em relação à sua image DrawableLeft
  • Grande atraso / atraso de UDP com o Android
  • NotificationManager.cancel (id) não está funcionando dentro de um receptor de transmissão
  • Ligair a canvas programaticamente
  • Crie um background transpairente de icons Android no eclipse
  • 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.