Android Listview定位getview Startapp广告

时间:2014-12-22 12:02:43

标签: android position ads startapp

我有Adapter类的列表视图。我需要在列表视图中点击显示Startapp.com插页式广告每隔5个位置,怎么样?我只是在这里发布示例代码,这不是一个完整的代码..

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;
}

1 个答案:

答案 0 :(得分: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();
        }
    }

希望这会对你有所帮助