我正处于应用程序的后期阶段,并且想知道如何让Inneractive广告发挥作用。我已经尝试过他们的教程而且没有展示广告。 这是代码
AndroidListViewActivity.java:
package com.androidhive.androidlistview;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.inneractive.api.ads.InneractiveAd;
import com.inneractive.api.ads.InneractiveAdListener;
import com.androidhive.androidlistview.AndroidListViewActivity;
import java.util.Hashtable;
import android.view.Gravity;
import android.widget.LinearLayout;
public class AndroidListViewActivity extends ListActivity {
LinearLayout linear;
InneractiveAd addedIaAd;
InneractiveAd bannerAd;
InneractiveAd rectangleAd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linear = new LinearLayout(this);
linear.setGravity(Gravity.CENTER_HORIZONTAL);
linear.setOrientation(LinearLayout.VERTICAL);
//adding banner ad - banner
Hashtable<InneractiveAd.IaOptionalParams, String> adData = new Hashtable<InneractiveAd.IaOptionalParams, String>();
adData.put(InneractiveAd.IaOptionalParams.Key_Keywords, "Entertainment");
InneractiveAd.displayAd(AndroidListViewActivity.this, linear, "MyCompany_MyApp", InneractiveAd.IaAdType.Banner, 60,adData,(InneractiveAdListener) AndroidListViewActivity.this);
setContentView(linear);
// storing string resources into Array
String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String product = ((TextView) view).getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
i.putExtra("product", product);
startActivity(i);
}
});
}
}
Singlelistitem.java:
package com.androidhive.androidlistview;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SingleListItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.single_list_item_view);
TextView txtProduct = (TextView) findViewById(R.id.product_label);
Intent i = getIntent();
// getting attached intent data
String product = i.getStringExtra("product");
// displaying selected product name
txtProduct.setText(product);
}
}
的xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="adobe_products">
<item>Adobe After Effects</item>
<item>Adobe Bridge</item>
<item>Adobe Dreamweaver</item>
<item>Adobe Edge</item>
<item>Adobe Fireworks</item>
<item>Adobe Flash</item>
<item>Adobe Photoshop</item>
<item>Adobe Premiere</item>
<item>Adobe Reader</item>
<item>Adobe Illustrator</item>
</string-array>
</resources>
来自logcat的错误:
java.lang.RuntimeException:无法启动活动ComponentInfo {com.androidhive.androidlistview / com.androidhive.androidlistview.AndroidListViewActivity}:java.lang.ClassCastException:com.androidhive.androidlistview.AndroidListViewActivity无法强制转换为com.inneractive .api.ads.InneractiveAdListener
程序中没有错误,但是当我在Eclipse ADT中运行应用程序时,它说应用程序已经意外停止。任何人都可以告诉我如何让inneractive广告横幅作为列表视图中的列表项工作这个计划。