ViewPager扩展PagerAdapter无法设置视图

时间:2016-12-13 05:56:35

标签: android android-viewpager

此类的代码无法在第0位显示视图,并且有时也显示无关数据。此视图寻呼机附加了tablayout。 我想知道为什么会发生这种情况,以及是否有其他方式来处理viewpager扩展PagerAdapter。如果我能了解另一个与PagerAdapter相关的课程,我会很高兴的。但不使用Fragment。

 public class JobcardListViewPagerAdapter extends PagerAdapter implements IWebServiceAdapter {

    Context mContext;
    LayoutInflater mLayoutInflater;
    List<TabLayoutDetails> tabLayoutDetailsList;
    ActiveJobCardListResponse activeJobCardListResponse;
    Activity activity;
    View itemView;
    WebService webService;

    public JobcardListViewPagerAdapter(Context context, List<TabLayoutDetails> tabLayoutDetailsList) {

        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.tabLayoutDetailsList = tabLayoutDetailsList;
        webService = new WebService();

    }

    public JobcardListViewPagerAdapter() {

    }

    @Override
    public int getCount() {
        return tabLayoutDetailsList.size(); // value of tabLayoutDetailsList.size() returning 10;


    }

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

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        itemView = mLayoutInflater.inflate(R.layout.active_job_card_list_view_pager_adapter, container, false);

        GetActiveJobCardList(position);

        container.addView(itemView);

        return itemView;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
    }


}

0 个答案:

没有答案