I'd like to have a list of items with a fixed ad at the bottom of the screen.
This is the quick and dirty code I have so far (Does not include ads yet):
public class SoundBoard extends ListActivity {
private SoundManager mSoundManager;
/** Called when the activity is first created. */
@Override
public void 开发者_JAVA百科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"
};
}
I will probably use the Admob sdk. What would be the best way of doing this?
Add setContentView(R.layout.soundboard);
to your onCreate method, then create two XML files in layout:
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>
and ad.xml which will contain your layout for the ad.
Create a new AdView from the AdMob SDK and set the new view as the footer for the list view. Something like:
lv.addFooterView(myAdMobView);
If you're looking for example layout that does what you're asking about, take a look at Scrolling Text Above Buttons, Buttons Fixed At Bottom.
精彩评论