1

How can I display banner ads intermittently in a gridview when I have a preset number of columns (3 on a phone and 4 on a tablet). I know a need a second layout for the banner ad of course.

But my question is more concerning how I can inflate this banner ad after some number of rows and make it fill what 3 or 4 columns would fill?

This is my current gridView adapter:

public class GridViewUpcomingAdapter extends BaseAdapter {

    private Context context;
    ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater = null;
    public ImageLoader imageLoader;
    public ImageView poster;
    private HashMap<String, String> mylist;
    public String url;
    public String posterPath;

    public GridViewUpcomingAdapter(Context a, ArrayList<HashMap<String, String>> d) {
        context = a;
        data = d;
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new ImageLoader(context.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (convertView == null)
            vi = inflater.inflate(R.layout.fragment_upcoming, null);

        poster = (ImageView) vi.findViewById(R.id.grid_item_image);

        mylist = new HashMap<String, String>();
        mylist = data.get(position);



        new DownloadImage().execute();

        return vi;
    }

    public class DownloadImage extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... string) {


            posterPath = (String) mylist.get("poster_path");
            url = "http://image.tmdb.org/t/p/w500" + posterPath;
            return null;

        }

        @Override
        protected void onPostExecute(String result) {
            imageLoader.DisplayImage(url, poster);
            super.onPostExecute(result);
        }
    }
}
Mat0
  • 1,165
  • 2
  • 11
  • 27
  • http://stackoverflow.com/questions/26841964/how-to-show-banner-ads-intermittently-in-gridview – TareQ Feb 29 '16 at 14:17

0 Answers0