android 列表加广告,android – 如何在列表视图中添加原生广告?

这是我的活动

我想在列表视图中插入原生广告.

我正在尝试按照本指南

https://github.com/StartApp-SDK/Documentation/wiki/android-advanced-usage但我觉得很难理解.

你可以帮我一把,也许可以举出代码示例吗?谢谢

活动

public class EpisodiActivity extends Activity {

private StartAppAd startAppAd = new StartAppAd(this);

public class ViewModel {

private String url;

private String name;

public ViewModel(String url, String name) {

this.url = url;

this.name = name;

}

public String getUrl() {

return this.url;

}

public void setUrl(String url) {

this.url = url;

}

public String getName() {

return this.name;

}

public void setName(String name) {

this.name = name;

}

public String toString() {

return this.name;

}

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// creazione fullscreen activity

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.episodi_activity);

String[] episodi = getIntent().getStringArrayExtra("Product");

String[] urls = getIntent().getStringArrayExtra("urls");

ListView mylist = (ListView) findViewById(R.id.listView1);

// And in this loop we create the ViewModel instances from

// the name and url and add them all to a List

List models = new ArrayList();

for (int i = 0; i < episodi.length; i++) {

String name = episodi[i];

String url = "No value";

if (i < urls.length) {

url = urls[i];

}

ViewModel model = new ViewModel(url, name);

models.add(model);

}

// Here we create the ArrayAdapter and assign it to the ListView

// We pass the List of ViewModel instances into the ArrayAdapter

final ArrayAdapter adapter = new ArrayAdapter(

this, android.R.layout.simple_list_item_1, models);

mylist.setAdapter(adapter);

mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView> arg0, View v, int position,

long id) {

// Here we get the ViewModel at the given position

ViewModel model = (ViewModel) arg0.getItemAtPosition(position);

// And the url from the ViewModel

String url = model.getUrl();

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

}

});

}

@Override

public void onResume() {

super.onResume();

startAppAd.onResume();

startAppAd.showAd();

}

@Override

public void onPause() {

super.onPause();

startAppAd.onPause();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值