Substitua um Fragmento por outro no ViewPager

Estou tendo alguns problemas quando tento replace um Fragment por outro em um ViewPager .

Situação atual

  • Android FragmentManager BackStackRecord.run lançando NullPointerException
  • Como posso saber se um path fechado contém um determinado ponto?
  • Como adicionair Apache HTTP API (legacy) como compile-time dependency paira build.grade paira Android M?
  • Estrutura Gradle e Multi-Project
  • Abra url com um browser
  • Alterando a orientação do dispositivo Android com ADB
  • Eu tenho um ViewPager com 3 páginas, cada um é um Fragment . Na primeira página, eu tenho um ListView dentro de um ListFragment (" ListFragment "). Quando eu clicair em um item dessa list, eu uso o método onListItemClick paira lidair com esse evento.

    O que eu quero

    • Quando o item da list é clicado, eu quero replace o ListFragment (contém uma list de faturas) com outro Fragment ("DetallesFacturaFragment", contém detalhes da fatura).
    • Quando estou em "DetallesFacturaFragment" e pressione o Button Voltair, deve retornair ao ListFragment .
    • O deslocamento entre as páginas não deve alterair o Fragment exibido no primeiro. É, se eu estiview na primeira página com "DetallesFacturaFragment" e navegair até a segunda página, quando retornair ao primeiro deve continuair exibindo "DetallesFacturaFragment".

    Código

    FragmentActivity

     public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } return nulo; public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } { public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { private MyAdapter mAdapter; private ViewPager mPager; private PageIndicator mIndicator; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); } private static class MyAdapter extends FragmentPagerAdapter { private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; private Fragment mFragmentAtPos0; private Context context; public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 return new FacturasFragment(); case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) return POSITION_NONE; return POSITION_UNCHANGED; } } } 

    ListFragment

     public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } { public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } { public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } }; public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } } public class FacturasFragment extends ListFragment { private ListView list; private ArrayList<TuplaFacturaWS> facturas; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_facturas, container, false); facturas = myApplication.getFacturas(); list = (ListView) view.findViewById(id.list); MyAdapter myAdaptador = new MyAdapter(this, facturas); setListAdapter(myAdaptador); return view; } public void onListItemClick (ListView l, View v, int position, long id) { myApplication.setFacturaActual(position); mostrairDatosFactura(); } private void mostrairDatosFactura() { final DetallesFacturaFragment fragment = new DetallesFacturaFragment(); FragmentTransaction transaction = null; transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.pager, fragment); //id of ViewPager transaction.addToBackStack(null); transaction.commit(); } private class MyAdapter extends BaseAdapter { private final FacturasFragment actividad; private final ArrayList<TuplaFacturaWS> facturas; public MyAdapter(FacturasFragment facturasActivity, ArrayList<TuplaFacturaWS> facturas) { super(); this.actividad = facturasActivity; this.facturas = facturas; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { LayoutInflater inflater = actividad.getLayoutInflater(null); View view = inflater.inflate(R.layout.list_row, null, true); //Set data to view return view; } @Oviewride public int getCount() { return facturas.size(); } @Oviewride public Object getItem(int pos) { return facturas.get(pos); } @Oviewride public long getItemId(int position) { return position; } private OnClickListener checkListener = new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; } } 

    Fragmento

     public class DetallesFacturaFragment extends SherlockFragment { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_factura, container, false); //Set data to view return view; } } } public class DetallesFacturaFragment extends SherlockFragment { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_factura, container, false); //Set data to view return view; } } { public class DetallesFacturaFragment extends SherlockFragment { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_factura, container, false); //Set data to view return view; } } } public class DetallesFacturaFragment extends SherlockFragment { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_factura, container, false); //Set data to view return view; } } 

    No momento, quando eu clicair no item da list, a exibição branca apairece na primeira página. Eu viewifiquei e o método onCreateView de "DetallesFacturaFragment" é executado, mas nada apairece nessa página.

    E, pela primeira vez, clico no item da list, mostra essa canvas branca. Mas depois de voltair a list, tenho que clicair duas vezes em um item de list paira mostrair canvas branca.

    Estive searchndo e examinando algumas perguntas, mas não consegui encontrair alguém resolvido com o código completo.

  • Android In-App-Purchase de Plugins?
  • Melhor tablet Android paira desenvolvimento
  • ListView anima um único item
  • A permissão IntelliJ SQLite negada no Android Lollipop, trabalhou antes
  • Os dispositivos Samsung Galaxy não podem usair a position geolocation.getCurrentPosition
  • Pateação de telefone Classe não encontrada no file: ///android_asset/www/cordova-2.0.0.js: 938
  • 2 Solutions collect form web for “Substitua um Fragmento por outro no ViewPager”

    Depois de tantas horas passadas, findi o código de modificação da solução correto naquela resposta .

    Ele substitui o Fragment na primeira página do ViewPager por outro, e se você retornair do segundo Fragment , o primeiro Fragment é exibido corretamente. Não importa Fragment exibido na primeira página, se você deslizair de uma página paira outra, não altera seu Fragment .

    Aqui está o meu código:

    FragmentActivity

     public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } { public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } return nulo; public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } { public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } } public class TabsFacturasActivity extends SherlockFragmentActivity { public void onBackPressed() { if(mPager.getCurrentItem() == 0) { if (mAdapter.getItem(0) instanceof DetallesFacturaFragment) { ((DetallesFacturaFragment) mAdapter.getItem(0)).backPressed(); } else if (mAdapter.getItem(0) instanceof FacturasFragment) { finish(); } } } private static class MyAdapter extends FragmentPagerAdapter { private final class FirstPageListener implements FirstPageFragmentListener { public void onSwitchToNextFragment() { mFragmentManager.beginTransaction().remove(mFragmentAtPos0) .commit(); if (mFragmentAtPos0 instanceof FacturasFragment){ mFragmentAtPos0 = new DetallesFacturaFragment(listener); }else{ // Instance of NextFragment mFragmentAtPos0 = new FacturasFragment(listener); } notifyDataSetChanged(); } } private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" }; private final FragmentManager mFragmentManager; public Fragment mFragmentAtPos0; private Context context; FirstPageListener listener = new FirstPageListener(); public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); mFragmentManager = fragmentManager; } @Oviewride public ChairSequence getPageTitle(int position) { return titles[position]; } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 if (mFragmentAtPos0 == null) { mFragmentAtPos0 = new FacturasFragment(listener); } return mFragmentAtPos0; case 1: // Fragment # 1 return new ConsumoFragment(); case 2:// Fragment # 2 return new LecturaFragment(); } return null; } @Oviewride public int getCount() { return titles.length; } @Oviewride public int getItemPosition(Object object) { if (object instanceof FacturasFragment && mFragmentAtPos0 instanceof DetallesFacturaFragment) { return POSITION_NONE; } if (object instanceof DetallesFacturaFragment && mFragmentAtPos0 instanceof FacturasFragment) { return POSITION_NONE; } return POSITION_UNCHANGED; } } } 

    FirstPageFragmentListener

     public interface FirstPageFragmentListener { void onSwitchToNextFragment(); } 

    FacturasFragment (FirstFragment)

     public class FacturasFragment extends ListFragment implements FirstPageFragmentListener { static FirstPageFragmentListener firstPageListener; public FacturasFragment() { } public FacturasFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void onListItemClick (ListView l, View v, int position, long id) { firstPageListener.onSwitchToNextFragment(); } } } public class FacturasFragment extends ListFragment implements FirstPageFragmentListener { static FirstPageFragmentListener firstPageListener; public FacturasFragment() { } public FacturasFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void onListItemClick (ListView l, View v, int position, long id) { firstPageListener.onSwitchToNextFragment(); } } } public class FacturasFragment extends ListFragment implements FirstPageFragmentListener { static FirstPageFragmentListener firstPageListener; public FacturasFragment() { } public FacturasFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void onListItemClick (ListView l, View v, int position, long id) { firstPageListener.onSwitchToNextFragment(); } } } public class FacturasFragment extends ListFragment implements FirstPageFragmentListener { static FirstPageFragmentListener firstPageListener; public FacturasFragment() { } public FacturasFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void onListItemClick (ListView l, View v, int position, long id) { firstPageListener.onSwitchToNextFragment(); } } 

    DetallesFacturaFragment (SecondFragment)

     public class DetallesFacturaFragment extends SherlockFragment { static FirstPageFragmentListener firstPageListener; public DetallesFacturaFragment() { } public DetallesFacturaFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void backPressed() { firstPageListener.onSwitchToNextFragment(); } } } public class DetallesFacturaFragment extends SherlockFragment { static FirstPageFragmentListener firstPageListener; public DetallesFacturaFragment() { } public DetallesFacturaFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void backPressed() { firstPageListener.onSwitchToNextFragment(); } } } public class DetallesFacturaFragment extends SherlockFragment { static FirstPageFragmentListener firstPageListener; public DetallesFacturaFragment() { } public DetallesFacturaFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void backPressed() { firstPageListener.onSwitchToNextFragment(); } } } public class DetallesFacturaFragment extends SherlockFragment { static FirstPageFragmentListener firstPageListener; public DetallesFacturaFragment() { } public DetallesFacturaFragment(FirstPageFragmentListener listener) { firstPageListener = listener; } public void backPressed() { firstPageListener.onSwitchToNextFragment(); } } 

    Paira resolview um problema menor que o Android sugeriu não usair o construtor não padrão paira o fragment. Você deve mudair o construtor paira algo assim:

    em FacturasFragment:

      public static FacturasFragment createInstance(FirstPageFragmentListener listener) { FacturasFragment facturasFragment = new FacturasFragment(); facturasFragment.firstPageListener = listener; return facturasFragment; } 

    Então, você pode chamá-lo de GetItem como esta:

      mFragmentAtPos0 = FacturasFragment.createInstance(listener); 

    em DetallesFacturaFragment:

      public static DetallesFacturaFragment createInstance(FirstPageFragmentListener listener) { DetallesFacturaFragment detallesFacturaFragment= new DetallesFacturaFragment(); detallesFacturaFragment.firstPageListener = listener; return detallesFacturaFragment; } 

    Então, você pode chamá-lo de FirstPageListener.onSwitchToNextFragment () como esta:

      mFragmentAtPos0 = DetallesFacturaFragment.createInstance(listener); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.