-1

我有适配器类的列表视图。我需要在列表视图中每点击 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;
}
4

1 回答 1

0

检查项目点击的位置并尝试这个

InterstitialAd mInterstitialAd = new InterstitialAd(context);
            mInterstitialAd.setAdUnitId("ur ad id");
            AdRequest adRequest = new AdRequest.Builder().build();
            mInterstitialAd.loadAd(adRequest);
            mInterstitialAd.setAdListener(new AdListener() {
                public void onAdLoaded() {
                    displayInterstitial();
                }
            });

public void displayInterstitial() {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        }
    }

希望对你有帮助

于 2014-12-22T12:12:53.897 回答