Just for kicks, what happens if you don't create a new fragment every time
you change tabs?  Only create it once, something like this tutorial:
http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/

Note, I'm not endorsing that tutorial or anything... I don't see anything
immediately wrong with your code (related to the tabs anyway) but I figured
this tutorial should work, and that is the main difference I see between
your code and this tutorial.

On Tue, Jan 12, 2016 at 9:37 AM Hugo Teijiz <hugo.tei...@gmail.com> wrote:

> MainActivity:
>     @Override
>     protected void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.activity_main);
>
>
> getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
>         App.setTrxNumber(0);
>         App.setContext(MainActivity.this);
>
>         if (!isOnline()) {
>             Toast.makeText(this, "No se ha Podido Conectar con el
> Servidor", Toast.LENGTH_LONG).show();
>             finish();
>         }
>
>         StrictMode.ThreadPolicy policy = new
> StrictMode.ThreadPolicy.Builder().permitAll().build();
>         StrictMode.setThreadPolicy(policy);
>
>         if (ContextCompat.checkSelfPermission(this,
> Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
> {
>             TelephonyManager mngr = (TelephonyManager)
> getSystemService(Context.TELEPHONY_SERVICE);
>             imei = mngr.getDeviceId();
>         } else {
>             ActivityCompat.requestPermissions(this,
>                     new String[]{Manifest.permission.READ_CONTACTS},
>                     REQUEST_READ_PHONE_STATE_PERMISSION);
>         }
>
>         try {
>             ContentResolver cr = getContentResolver();
>             MostrarSettings(cr, true);
>         } catch (Exception e) {
>             Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
>         }
>
>         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
>         setSupportActionBar(toolbar);
>
>         final TabLayout tabLayout = (TabLayout)
> findViewById(R.id.tab_layout);
>         tabLayout.addTab(tabLayout.newTab().setText("PENDIENTES"));
>         tabLayout.addTab(tabLayout.newTab().setText("CONFIRM"));
>         tabLayout.addTab(tabLayout.newTab().setText("RECHAZADOS"));
>         tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
>
>         final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
>         final PagerAdapter adapter = new PagerAdapter
>                 (getSupportFragmentManager(), tabLayout.getTabCount());
>         viewPager.setAdapter(adapter);
>         viewPager.addOnPageChangeListener(new
> TabLayout.TabLayoutOnPageChangeListener(tabLayout));
>         tabLayout.setOnTabSelectedListener(new
> TabLayout.OnTabSelectedListener() {
>             @Override
>             public void onTabSelected(TabLayout.Tab tab) {
>                 viewPager.setCurrentItem(tab.getPosition());
>             }
>
>             @Override
>             public void onTabUnselected(TabLayout.Tab tab) {
>
>             }
>
>             @Override
>             public void onTabReselected(TabLayout.Tab tab) {
>                 viewPager.setCurrentItem(tab.getPosition());
>             }
>         });
>     }
>
> PagerAdapter.java:
> import android.support.v4.app.Fragment;
> import android.support.v4.app.FragmentManager;
> import android.support.v4.app.FragmentStatePagerAdapter;
>
> /**
>  * Created by Hugo on 08/01/2016.
>  */
> public class PagerAdapter extends FragmentStatePagerAdapter {
>     int mNumOfTabs;
>
>     public PagerAdapter(FragmentManager fm, int NumOfTabs) {
>         super(fm);
>         this.mNumOfTabs = NumOfTabs;
>     }
>
>     @Override
>     public Fragment getItem(int position) {
>
>         switch (position) {
>             case 0:
>                 PendFragment tab1 = new PendFragment();
>                 return tab1;
>             case 1:
>                 ConfirmFragment tab2 = new ConfirmFragment();
>                 return tab2;
>             case 2:
>                 RejectFragment tab3 = new RejectFragment();
>                 return tab3;
>             default:
>                 return null;
>         }
>     }
>
>     @Override
>     public int getCount() {
>         return mNumOfTabs;
>     }
> }
>
> El martes, 12 de enero de 2016, 12:26:10 (UTC-3), MagouyaWare escribió:
>
>> Code?
>>
>> On Tue, Jan 12, 2016, 9:16 AM Hugo Teijiz <hugo....@gmail.com> wrote:
>>
> Hello to everyone.
>>>
>>> I develop an Android application with TabLayout. The App has 3 tabs.
>>> When I click over Tab 1 (Index 0) and Tab 3 (Index 2) the view refresh
>>> great, but when I click over Tab 2 (Index 1) nothing happens.
>>>
>>> OnSelectedTab Listener executed correctly, and execute then
>>> setCurrentItem of viewPager, but onCreateView of Fragment doesn't execute.
>>>
>>> Any ideas?
>>>
>>> Thanks in advance
>>>
>>> Regards!!
>>>
>>> Hugo
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to android-developers+unsubscr...@googlegroups.com.
>>>
>> To post to this group, send email to android-d...@googlegroups.com.
>>
>>
>>> Visit this group at https://groups.google.com/group/android-developers.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/android-developers/4ac4ec61-7c1a-49f1-aa6f-974b19e4dd14%40googlegroups.com
>>> <https://groups.google.com/d/msgid/android-developers/4ac4ec61-7c1a-49f1-aa6f-974b19e4dd14%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to android-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/android-developers/a96dd40d-8634-4996-86d7-b877e2124aa2%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/a96dd40d-8634-4996-86d7-b877e2124aa2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CAOq06s82HHknFUfMiAon9oPURXiboqqokgW284HKS9g-YVQ5vA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to