Android Listview Position getview Startapp ads

588 views Asked by At

I have list view with Adapter class. i need show Startapp.com Interstitial Ads every 5th position clicked in list view, how? I just post sample codes here this is not a full code..

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

There are 1 answers

2
Mustanser Iqbal On BEST ANSWER

check position on item click and try this

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

hope this will help you