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