Note that there are some explanatory texts on larger screens.

plurals
  1. POListview Admob Layout
    text
    copied!<p>My Layout XML for my Admob is causing some errors.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;com.google.ads.AdView android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxxxxxxx" ads:loadAdOnCreate="true" /&gt; &lt;ListView android:id="@+id/list_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/sailor" /&gt; &lt;TextView android:id="@+id/row" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/trans" android:padding="10dp" android:textColor="@color/menu_text" android:textSize="22sp" android:textStyle="normal" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Activity</p> <pre><code>public class ListViewOne extends Activity { // we use a string to hold the name of our extra, // it must include the full package name public final static String ID_EXTRA = "com.faarn.navyslang._ID"; private DatabaseHelper dbDataBaseHelper = null; private Cursor ourCursor = null; private DataBaseAdapter adapter = null; @Override public void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); setContentView(R.layout.main); // this is our ListView element, obtained by id from our XML Layout ListView myListView = (ListView) findViewById(R.id.list_view); // create our database Helper dbDataBaseHelper = new DatabaseHelper(this); // we call the create right after initializing the helper, just in // case // they have never run the app before dbDataBaseHelper.createDatabase(); // // open the database!! Our helper now has a SQLiteDatabase database // object dbDataBaseHelper.openDataBase(); // get our cursor. A cursor is a pointer to a dataset, in this case // a set of results from a database query ourCursor = dbDataBaseHelper.getCursor(); // tell android to start managing the cursor // we do this just incase our activity is interrupted or ends, we // want the activity // to close and deactivate the cursor, as needed startManagingCursor(ourCursor); // create our adapter adapter = new DataBaseAdapter(ourCursor); // set the adapter!!! myListView.setAdapter(adapter); // this is how we know what to do when a list item is clicked myListView.setOnItemClickListener(onListClick); } catch (Exception e) { // this is the line of code that sends a real message to the Log Log.e("ERROR", "ERROR IN CODE: " + e.toString()); // this is the line that prints out the location // the code where the error occurred. e.printStackTrace(); } } private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Create our intent, as per usual Intent i = new Intent(ListViewOne.this, ListViewTwo.class); i.putExtra(ID_EXTRA, String.valueOf(id)); TabGroupActivity parentActivity = (TabGroupActivity)getParent(); parentActivity.startChildActivity("ListViewTwo", i); } }; class DataBaseAdapter extends CursorAdapter { DataBaseAdapter(Cursor c) { super(ListViewOne.this, c); } @Override // this is a CursorAdapter // instead of Using a getView and if(row=null) // we use a bindView and newView calls // we can get away with this because CursorAdapters have // a default implementation of getView that calls bindView and newView // as needed. This makes our code a bit cleaner, and is the better way // to // do this public void bindView(View row, Context ctxt, Cursor c) { DataBaseHolder holder = (DataBaseHolder) row.getTag(); holder.populateFrom(c, dbDataBaseHelper); } @Override public View newView(Context ctxt, Cursor c, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row = inflater.inflate(R.layout.main, parent, false); DataBaseHolder holder = new DataBaseHolder(row); row.setTag(holder); return (row); } } static class DataBaseHolder { private TextView name = null; DataBaseHolder(View row) { name = (TextView) row.findViewById(R.id.row); } void populateFrom(Cursor c, DatabaseHelper r) { name.setText(r.getName(c)); } } } </code></pre> <p>The Admob is sitting at the top as expected but is also appearing between every row of my list. I have looked at lots of other questions about this but have not been able to correct it. Any help appreciated.</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