0

我在我的應用程序中有一個pagerAdapter,我想在每一行被選中時調用並獲取數據,並填充recycleview中的數據。android -make view當viewpager在PagerAdapter上被選中

到目前爲止,我已經做了我的viewpager,併爲每個孩子做了recycleview,現在,我想調用並在選擇每個視圖時獲取json。這是我的代碼:

private static class CheesePagerAdapter extends PagerAdapter { 
    private final ArrayList<CharSequence> mCheeses = new ArrayList<>(); 

    public void addTab(String title) { 
     mCheeses.add(title); 
     notifyDataSetChanged(); 
    } 

    @Override 
    public int getCount() { 
     return mCheeses.size(); 
    } 

    @Override 
    public int getItemPosition(Object object) { 
     final Item item = (Item) object; 
     final int index = mCheeses.indexOf(item.cheese); 
     return index >= 0 ? index : POSITION_NONE; 
    } 

    @Override 
    public Object instantiateItem(ViewGroup container, int position) { 
     final RecyclerView rc=new RecyclerView(container.getContext()); 
     RtlGridLayoutManager mLayoutManager = new RtlGridLayoutManager(container.getContext() 
       , numColumns); 
     rc.setLayoutManager(mLayoutManager); 

     container.addView(rc, ViewGroup.LayoutParams.MATCH_PARENT, 
       ViewGroup.LayoutParams.MATCH_PARENT); 

     Item item = new Item(); 
     item.cheese = mCheeses.get(position); 
     item.view = rc; 
     return item; 
    } 

    @Override 
    public boolean isViewFromObject(View view, Object object) { 
     final Item item = (Item) object; 
     return item.view == view; 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     return mCheeses.get(position); 
    } 

    @Override 
    public void destroyItem(ViewGroup container, int position, Object object) { 
     final Item item = (Item) object; 
     container.removeView(item.view); 
    } 

    public void getData(String id) { 

    } 

    private static class Item { 
     RecyclerView view; 
     CharSequence cheese; 
    } 
} 

我的方法,那的getData確定選擇哪個位置,現在我想訪問其容器和填充數據。

我該怎麼辦?

回答

0

的getData嘗試recyclerView的適配器設置數據,並以通知的數據調用notifyDataSetChanged()兩個recyclerview和pageadapter的適配器被更換後

相關問題