如何在gridview中间歇性地展示横幅广告?

时间:2015-10-15 18:14:16

标签: java android gridview adapter ads

如果我有预设的列数(手机上有3个,平板电脑上有4个),如何在网格视图中间歇性地显示横幅广告。 我知道当然需要横幅广告的第二种布局。

但我的问题更多的是关于如何在一些行之后对这个横幅广告进行充气并填充3或4列会填充哪些广告?

这是我当前的gridView适配器:

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

0 个答案:

没有答案