2016-03-31 21 views
1

numaralı instances numaralı instances numaralı telefona sahip olmakla birlikte list numaralı ürüne ait farklı veriler mevcuttur. Ve current page'u almak istiyorum, böylece başlığı kullanarak data'u değiştirebilirim. Sorun şu ki: mViewPager.getCurrentItem())method her zaman çağrılmıyor. oncreateview yılındaBölüm Sayfa Bağdaştırıcısı getCurrentItem başlığı

i var: her zaman current madde title olsun böylece

jours2 = new ArrayList<>(); 
rv = (RecyclerView) rootView.findViewById(R.id.recyclerView); 
rv.setLayoutManager(new LinearLayoutManager(getContext())); 

adapter = new MyAdapter(jours2); 
rv.setAdapter(adapter); 
String test= mSectionsPagerAdapter.getPageTitle(mViewPager.getCurrentItem()).toString(); 

for (Cours c : jours) 
{ 


    if (c.jour==test) 
    { 
     jours2.add(c); 

    } 
} 
adapter.notifyDataSetChanged(); 

Yani ben kodumu değiştirebilir.

SectionPageAdapter:

public class SectionsPagerAdapter extends FragmentPagerAdapter { 
    ArrayList<Fragment> fragments = new ArrayList<>(); 
    ArrayList<String> titles = new ArrayList<>(); 
    public SectionsPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 
    public void AddFragment(Fragment fragment,String title) 
    { 
     fragments.add(fragment); 
     titles.add(title); 
    } 
    @Override 
    public Fragment getItem(int position) { 
     // getItem is called to instantiate the fragment for the given page. 
     // Return a PlaceholderFragment (defined as a static inner class below). 
     return fragments.get(position); 


    } 

    @Override 
    public int getCount() { 
     // Show 3 total pages. 
     return fragments.size(); 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     return titles.get(position); 
    } 
} 
+0

mSectionPagerAdapter kodunuzu yükleyebilir misiniz –

+0

@RaviTeja I cevabımı güncelledim – yoyani

cevap

0

Sen konumunu belirlemeye

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 
      @Override 
      public void onTabSelected(TabLayout.Tab tab) { 
       tab.getPosition();  
      } 

      @Override 
      public void onTabUnselected(TabLayout.Tab tab) { 

      } 

      @Override 
      public void onTabReselected(TabLayout.Tab tab) { 

      } 
     }); 

almak için bu kullanabilir veya sadece tabLayout.getSelectedTabPosition() kullanabilirsiniz.

İlgili konular