为什么不显示TAB的内容呢
打断点,显示我的mViews 为0
打断点,显示我的mViews 为0
2016-12-30
private void initView() {
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mTabWeChat = (LinearLayout) findViewById(R.id.tab_wechat_ll);
mTabFriend = (LinearLayout) findViewById(R.id.tab_friend_ll);
mTabAddress = (LinearLayout) findViewById(R.id.tab_address_ll);
mTabSetting = (LinearLayout) findViewById(R.id.tab_settings_ll);
mBtnWeChat = (ImageButton) findViewById(R.id.tab_wechat_btn);
mBtnFriend = (ImageButton) findViewById(R.id.tab_friend_btn);
mBtnAddress = (ImageButton) findViewById(R.id.tab_address_btn);
mBtnSetting = (ImageButton) findViewById(R.id.tab_settings_btn);
LayoutInflater mInflater = LayoutInflater.from(this);
View tab01 = mInflater.inflate(R.layout.tab1_main, null);
View tab02 = mInflater.inflate(R.layout.tab2_main, null);
View tab03 = mInflater.inflate(R.layout.tab3_main, null);
View tab04 = mInflater.inflate(R.layout.tab4_main, null);
mViews.add(tab01);
mViews.add(tab02);
mViews.add(tab03);
mViews.add(tab04);
mAdapter = new PagerAdapter() {
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(mViews.get(position));// 移除view
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = mViews.get(position); // 初始view
container.addView(view);
return view;
}
@Override
public int getCount() {
return mViews.size(); // 获取view大小
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
};
mViewPager.setAdapter(mAdapter);
}你可以参照这个代码检查下。
举报