包括列表下方的固定广告

时间:2011-06-04 20:42:27

标签: android admob ads

我想在屏幕底部找到固定广告的项目列表。

这是我到目前为止快速而肮脏的代码(尚未包含广告):

public class SoundBoard extends ListActivity {
private SoundManager mSoundManager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

      setListAdapter(new ArrayAdapter<String>(this, R.layout.soundboard_item, CLIPS_STRINGS));



      ListView lv = getListView();

      mSoundManager = new SoundManager();
      mSoundManager.initSounds(getBaseContext());
      mSoundManager.addSound(1, R.raw.bad_seasons);
      mSoundManager.addSound(2, R.raw.friend_at_airport);

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          // When clicked, show a toast with the TextView text
            String selection;
            selection = (String) ((TextView) view).getText();
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();


            if (selection == "Bad Seasons")
                mSoundManager.playSound(1);
            if (selection == "Friend at Airport")
                mSoundManager.playSound(2);

        }
      });
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_HOME)){
        finish();
    }
    if ((keyCode == KeyEvent.KEYCODE_BACK)){
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

static final String[] CLIPS_STRINGS = new String[] {
    "Bad Seasons", "Friend at Airport"
};

}

我可能会使用Admob sdk。这样做的最佳方式是什么?

3 个答案:

答案 0 :(得分:2)

setContentView(R.layout.soundboard);添加到onCreate方法,然后在布局中创建两个XML文件:

soundboard.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
    <ListView
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_weight="1"/>
    <include layout="@layout/ad"/>
</LinearLayout>

和ad.xml,其中包含广告的布局。

答案 1 :(得分:0)

从AdMob SDK创建新的AdView,并将新视图设置为列表视图的页脚。类似的东西:

lv.addFooterView(myAdMobView);

答案 2 :(得分:0)

如果您正在寻找能够满足您要求的示例布局,请查看Scrolling Text Above Buttons, Buttons Fixed At Bottom