I have a list which displays information taken form my SQLite Database, everything works fine. I want to place an advert banner at the top of the List and have it in the XML layout as I do with my other activity's but the adverts are treated like the list text views and repeated inside each list element along with the database information.
I have experimented with the XML layout code for a few hours and read up on other solutions, but nothing seems to be working, I am stumped. Here is my class code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScoresDbAdapter.DatabaseHelper helper = new ScoresDbAdapter.DatabaseHelper(this);
database = helper.getWritableDatabase();
Cursor data = database.query("scores", fields, null, null, null, null, null);
dataSource = new SimpleCursorAdapter(this, R.layout.highscores, data, fields, new int[] { R.id.first, R.id.last });
ListView view = getListView();
view.setHeaderDividersEnabled(true);
view.addHeaderView(getLayoutInflater().inflate(R.layout.highscores, null));
setListAdapter(dataSource);
}
Here is my XML layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/rowLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a151868c65661b8"
ads:loadAdOnCreate="true" />
<TextView
android:id="@+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="First name" />
<TextView
android:id="@+id/last"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:text="Last name" />
</RelativeLayout>
I tried nesting layouts in a layout to separate the ads and text views but I am not actually sure I will be able to accomplish what I need to do, any advice is appreciated.