首页 > 其他 > 详细

一个没有main函数的 HelloWorld ... ...

时间:2014-03-27 14:55:40      阅读:449      评论:0      收藏:0      [点我收藏+]

使用ViewPager,运行后Logcat报出如下错误

No view found for id 0x7f080005 (id/view_pager) for fragment AdvertisementImageFragment{419e41d0 #0 id=0x7f080005 android:switcher:2131230725:0}

当时十分纠结为什么找不到view_page的定义,但是明明已经在xml中做好了定义

                   <FrameLayout
		         android:layout_width="match_parent"
		         android:layout_height="244dp"
		         android:layout_gravity="center"
		         android:background="@drawable/car_taxi_vendor_advertisement_bg"
		         android:baselineAligned="false" >
		         <android.support.v4.view.ViewPager
		             android:id="@+id/view_pager"
		             android:layout_width="wrap_content"
		             android:layout_height="wrap_content" />
		         <com.**.view.car.CirclePageIndicator
		             android:id="@+id/indicator"
		             android:layout_width="match_parent"
		             android:layout_height="wrap_content"
		             android:layout_marginBottom="12dp"
		             android:layout_gravity="center_horizontal|bottom" />
		     </FrameLayout>

项目场景: 点击某Activity的Button后,弹出一个居中的小View,在View里有多个可以滑动展示的图片。

最开始解决方案: 使用PopupWindwos,把如上的布局inflator后,赋值给PopupWindows的contentview。ViewPager的Adapter使用的是继承于FragmentAdapter的类。

contentView = inflater.inflate(R.layout.car_taxi_vendor_advertisement_view, null, false);
popupWindow.setContentView(contentView);
mBannerAdapter = new VendorAdvertisementImageAdapter(baseActivity.getSupportFragmentManager, icons, mImageFetcher);
pager.setAdapter(mBannerAdapter);

运行后,始终提示找不到view_pager的定义。

错误原因:因为FragmentAdapter传入的是Activity的FragmentManger,所以默认是在Activity的布局xml中寻找ViewPager的定义,但是实际上它是在弹出的View里定义的。

解决办法:放弃PopupWindows,使用FragmentDialog。注意:在new FragmentAdapter传入getChidFragmentManager。

mBannerAdapter = new VendorAdvertisementImageAdapter(getChildFragmentManager(), icons, mImageFetcher);
		pager.setAdapter(mBannerAdapter);




一个没有main函数的 HelloWorld ... ...,布布扣,bubuko.com

一个没有main函数的 HelloWorld ... ...

原文:http://blog.csdn.net/jack_wong2010/article/details/22270667

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!