I don't see the ListFrangment on FragmentPageAdapter after reload the fragment. I have a sliding menu with 3 options, when I click a one options, the fragment change for FragmentPageAdapter and load the ListFragment in a tab. The problem starts When I click again in the same option... the fragment change but the loaded fragment is empty, any list...

Does anyone know that can happen?

the code is: is a code exemple..

The code on call a FragmentPageAdapter...

public class MyListaCompra extends Fragment  {

View gv;
private static final String[] CONTENT = new String[] {"Pendientes","Realizadas" };

public static Intent newInstance(Activity activity,int pos) {
    Intent intent = new Intent(activity, MyListaCompra.class);
    return intent;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

     Log.i("Truiton FragmentList", "CREO LA VISTA");
    gv = inflater.inflate(R.layout.inicio,container, false);

    gv.setBackgroundResource(android.R.color.white);        
    FragmentPagerAdapter adapter = new GoogleMusicAdapter(getActivity().getSupportFragmentManager());
    ViewPager pager = (ViewPager) gv.findViewById(R.id.pager);
    pager.setAdapter(adapter);

    TabPageIndicator indicator = (TabPageIndicator) gv.findViewById(R.id.indicator);
    indicator.setViewPager(pager);

    return gv;
}

@Override
public void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
       Log.i("Truiton FragmentList", "ESTOY EN PAUSE");

}
@Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
      Log.i("Truiton FragmentList", "ESTOY EN RESUME");
}
@Override
public void onDestroyView() {
    // TODO Auto-generated method stub
    super.onDestroyView();
      Log.i("Truiton FragmentList", "VistaDestruida!");
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.menu, menu);
}




class GoogleMusicAdapter extends FragmentPagerAdapter {
    public GoogleMusicAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {

        return FragmentListaPendiente.init(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return CONTENT[position % CONTENT.length].toUpperCase();
    }

    @Override
    public int getCount() {
      return CONTENT.length;
    }

    }
}

The code on inflate a FragmentPageAdapter with ListFragment

public class FragmentListaPendiente extends ListFragment{

int fragNum;

private Bundle savedState = null;

String arr[] = { "dates","exemple","1" };

public static FragmentListaPendiente init(int val) {
    FragmentListaPendiente truitonList = new FragmentListaPendiente();

    // Supply val input as an argument.
    Bundle args = new Bundle();
    args.putInt("val", val);
    truitonList.setArguments(args);

    return truitonList;
}

 @Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
     fragNum = getArguments() != null ? getArguments().getInt("val") : 1;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    return inflater.inflate(R.layout.list,null);

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, arr));
    this.getListView().setTextFilterEnabled(true);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    // TODO Auto-generated method stub
    super.onSaveInstanceState(outState);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Log.i("Truiton FragmentList", "Item clicked: " + id);
    }
}

Thanks

有帮助吗?

解决方案

I investigate for this question and I solve the problem.... the problem is:

FragmentPagerAdapter adapter = new GoogleMusicAdapter(getActivity().getSupportFragmentManager());

For solve this problem:

FragmentPagerAdapter adapter = new GoogleMusicAdapter(getChildFragmentManager());

information source:

FragmentPagerAdapter inside Fragment

Navigating back to FragmentPagerAdapter -> fragments are empty

Thanks =)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top