Populating a GridView with ImageViews dynamically/programmatically using a ImageAdapter

半城伤御伤魂 提交于 2019-12-03 15:28:32

You are missing a key part.

When you use an Adapter you have a method called notifyDataSetChanged(). The logic you are missing there is the following:

When creating the Adapter for the GridView stay with a reference for the list that the adapter will use. Something like:

private ArrayList<Photo> mPhotos;
private BaseAdapter mAdapter;
private GridView mGridView;

onCreate:

/* other things here */

mAdapter = new MyAdapter(mPhotos);
mGridView.setAdapter(mAdapter);

What you addPhoto should do is the following:

mPhotos.add(photo);
mAdapter.notifyDataSetChanged();

That's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!