我正在尝试使用PagerAdapter实现viewpager重写方法isViewFromObject
最初为同一视图调用两次。
ViewPagerAdapater.java
public class ViewPagerAdapater extends PagerAdapter {
HashMap<Integer,List<Sites>> mSiteList = null;
Context mContext = null;
public ViewPagerAdapater(Context context, HashMap<Integer,List<Sites>> siteList){
mSiteList = siteList;
mContext = context;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.viewpager_mobile_single, container, false);
container.addView(layout);
return layout;
}
@Override
public int getCount() {
return mSiteList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
Rect rec =new Rect();
if(view == object){
CustomViewPageChild mSelectedChild = (CustomViewPageChild)view;
if(view.getGlobalVisibleRect(rec))
{
System.out.println("View Visible true "+rec.flattenToString()); //this is printing two times
}
}
return view == object;
}
@Override
public CharSequence getPageTitle(int position) {
return super.getPageTitle(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}