2つのアクティビティで使用される一般的なフラグメント
public class Ads extends Fragment {
private View rootView ;
private MoPubView adView ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.ads, container, true) ;
adView = (MoPubView) rootView.findViewById(R.id.adView) ;
adView.setAdUnitId(LogoQuizUtil.MOPUB_AD_UNIT);
adView.loadAd();
return rootView;
}
}
フラグメントレイアウト
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<com.mopub.mobileads.MoPubView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:gravity="bottom" />
</LinearLayout>
このフラグメントを含める他のレイアウト
<fragment
android:id="@+id/ads"
android:name="myPackage.Ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" />
初めてsetContentView(R.layout.ads)を呼び出すと、例外が発生しません。2番目のアクティビティがfragementactivity(Ads)を呼び出すと、setContentView(R.id.ads)で例外が発生します。
私が得る例外は
08-07 09:38:30.359: W/System.err(975): java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage/mypackage.SecondActivity}: android.view.InflateException: Binary XML file line #263: Error inflating class fragment