Id like to include AdMobs ads in my app, but Im not sure how to add them.
My main activity calls setContentView on my main.xml, but my main.xml consists of only one ListView
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>
Adding the adview to the layout,
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.t3hh4xx0r.romcrawler"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" >
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
</ListView>
of course causes a force close on launch, as listViews aren’t allowed to have child layouts.
Whats the best way to get around this? Creating the ad view in java? And if so, could you provide some example code of how I would create it?
Thank you in advance!
Create a layout like this: This way the ad will show at the bottom. By setting the weightSum to 1 and then saying the weight of the listview is 1 it will take all space that is left after creating the ad.