0

Below is the xml which I am inflating dynamically in Fragment. However when I am doing this,

NativeAppInstallAdView add = (NativeAppInstallAdView) contentView.findViewById(R.id.adView);

The add reference is coming null where other views like

ImageView imgLogo = (ImageView) contentView.findViewById(R.id.ivLogo);

are working fine. I cannot find out exactly why it is happening here. Any help wil be great.

<com.google.android.gms.ads.formats.NativeAppInstallAdView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/linearAdView"
        android:layout_width="match_parent"
        android:focusable="true"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/ivLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="1dp">

                    <TextView
                        android:id="@+id/tvStore"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true" />

                    <TextView
                        android:id="@+id/tvPrice"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true" />
                </RelativeLayout>

            </LinearLayout>
        </LinearLayout>

        <ImageView
            android:id="@+id/ivImage"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="2dp"
            android:background="#00FFFFFF"
            android:scaleType="center" />

        <Button
            android:id="@+id/btnAction"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />
    </LinearLayout>

</com.google.android.gms.ads.formats.NativeAppInstallAdView>
Rocket
  • 11
  • 1
  • 5

0 Answers0