2014-02-24 133 views
0

你好,我有我的應用程序中的片段viewpager。我的問題是點擊一些按鈕,我想通過seriazlizable到viewpageradapter(在構造函數的幫助下)。適配器必須獲得可序列化的通行證才能對其進行分段並更新其視圖。最後我想將更新後的片段設置爲viewpager,但沒有任何反應。該視圖不會更新。請幫助ViewPager不更新其視圖

public class ViewPagerAdapter extends FragmentPagerAdapter { 


     private Bank myobject; 

    public ViewPagerAdapter(FragmentManager fm,Bank object) { 
     super(fm); 
     myobject = object; 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public Fragment getItem(int item) { 
     // TODO Auto-generated method stub 
     switch (item) { 
     case 0: 
      CurrencyFragment myFragment = new CurrencyFragment(); 
      Bundle args = new Bundle(); 
      args.putSerializable("message", myobject); 
      String code = myobject.getCode(); 
      Log.i("TAG","kodiiiiiiiiiiiiiiii"+ code); 
      myFragment.setArguments(args); 


      return myFragment; 

     default: 
      // The other sections of the app are dummy placeholders. 
      Fragment fragment = new CurrencyFragment(); 
      return fragment; 
    } 

    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 2; 
    } 

,並在MainActivity

mDrawerList.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
        long arg3) { 
       // TODO Auto-generated method stub 
       getBanks(position); 


      } 
     }); 



public void getBanks(final int pos) { 
     new AsyncTask<Integer, Void, List<Bank>>() { 



      @Override 
      protected List<Bank> doInBackground(Integer... params) { 

       return mGeoCurrency.getBanks("en").getData(); 
      } 

      @Override 
      protected void onPostExecute(List<Bank> banksList) { 
       super.onPostExecute(banksList); 
       try { 
        mListOfBanks = banksList; 
        mBankAdapter = new BankAdapter(getApplicationContext(), 
          R.layout.drawer_layout, mListOfBanks); 
        mDrawerList.setAdapter(mBankAdapter); 
        Bank nBank = mListOfBanks.get(pos); 

        Log.i("tag","kodiiiiiiiiiiiiii"+nBank.getCode()); 
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),nBank); 
        mViewpager.setAdapter(pagerAdapter); 
       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 
     }.execute(); 
    } 

回答

0

嘗試尋呼機適配器上調用notifyDataSetChangedref)問它來刷新自己的看法。

適配器將重新創建視圖,在創建碎片時再次調用適配器的getItem()方法。