Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding AdView to a class that extends ListActivity
    text
    copied!<p>I'm using AdMob for my Android apps. And I have wanted to add a AdView to an Activity that extends ListActivity.</p> <p>I have tried using <code>getListView().addHeaderView(my_ad_view)</code> but that doesn't seem to work.</p> <p>Any idea how to achieve this? As I'm very new to this field any help will be greatly appreciated. Thanks.</p> <p>Here is my code:</p> <p>This activity starts like:</p> <pre><code>public class Home extends ListActivity { /* Code */ } </code></pre> <p>The <code>onCreate()</code> function:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the list items. The method populateList() reads the items from the database // and returns a String array. setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, populateList())); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { goToTasks(String.valueOf(getListAdapter().getItem(position))); } }); lv.setCacheColorHint(0); lv.setBackgroundResource(R.drawable.fmn_background_300); registerForContextMenu(getListView()); refreshList(); // Here is the AdView code AdView adView = new AdView(this, AdSize.BANNER, FMN.ADMOB_ID); LinearLayout ll = (LinearLayout)findViewById(R.id.ll_admob); ll.addView(adView); getListView().addHeaderView(ll); adView.loadAd(new AdRequest()); } </code></pre> <p>I have set the Permissions and have declared the activities in the Manifest as required.</p> <p>In the <code>populateList()</code> method, I have only obtained a <code>Cursor</code> and then do some manipulation work and finally returned a <code>String</code> array.</p> <p>So what am I doing wrong? The app just exits when this activity is loaded.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload