ViewPager不会更新其视图

时间:2014-02-24 19:12:08

标签: android android-fragments

您好我的应用程序中有一个视图片段的片段。我的问题是单击某个按钮我想将seriazlizable传递给viewpageradapter(在构造函数的帮助下)。适配器必须获取可序列化传递给片段并更新它的视图。最后我想将这个带有更新片段的适配器设置到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;
    }

和主要活动

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();
    }

1 个答案:

答案 0 :(得分:0)

尝试在寻呼机适配器上调用notifyDataSetChangedref),要求其刷新其视图。

适配器将重新创建视图,在创建片段时再次调用适配器的getItem()方法。