我有适配器类的列表视图。我需要在列表视图中每点击 5 个位置显示 Startapp.com 插页式广告,如何?我只是在这里发布示例代码,这不是完整的代码..
MainActivity.java
public class Search extends Activity implements OnItemClickListener,
OnScrollListener {
private StartAppAd startAppAd = new StartAppAd(this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
StartAppSDK.init(this, "xxxxxx", "xxxxxx", true);
listView = (ListView) findViewById(R.id.listview);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
footer = (View) inflater.inflate(R.layout.footer, null);
listView.addFooterView(footer);
objAdapter = new NewsRowAdapter(Latest.this, R.layout.row,
mainArrayList);
listView.setAdapter(objAdapter);
listView.setOnScrollListener(this);
listView.setOnItemClickListener(this);
if (Utils.isNetworkAvailable(Latest.this)) {
task = new MyTask();
task.execute(feed);
} else {
showToast("No Network Connection!!!");
}
}
NewsRowAdapter.java
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(row, null);
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if ((items == null) || ((position + 1) > items.size()))
return view;
objBean = items.get(position);
holder.tvTitle = (TextView) view.findViewById(R.id.title);
if (holder.tvTitle != null && null != objBean.getTitle()
&& objBean.getTitle().trim().length() > 0) {
holder.tvTitle.setText(Html.fromHtml(objBean.getTitle()));
}
if (position % 5 == 0) {
//HOW CAN I ADD STARTAPP ADS HERE
}
return view;
}