将 Urls 转换为 imageviews 并动态添加到 gridview
Converting Urls to imageviews and add dynamically to gridview
我是 Android 的新手,我需要一些帮助我想通过向 imageAdapter 发送一个字符串数组 url 来设置一个带有 3 个图像按钮的 gridview,我首先使用 urls 来自网络服务 ans 将它们返回到我的片段 class,其中放置了 gridview。 arraylist 由具有 url 字符串集的对象组成。我不知道如何用这些 url 加载 gridview,我应该将它们转换为可绘制对象吗?我看到一些关于使用 asynchtask 的帖子?有人可以帮我吗?我实际上需要图像按钮,或者我可以将点击侦听器连接到图像视图吗?
下载 urls 表单 webservice
后,在片段 class 中启动方法
@Override
public void updateScreenMovies(ArrayList<Movie> movies) {
gvNieuw.setAdapter(new ImageAdapter(getActivity(),movies));
}
ImageAdapter class:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Movie> movies;
Drawable[] drawableArray = new Drawable[3];
public ImageAdapter(Context c, ArrayList<Movie> movies) {
mContext = c;
this.movies = movies;
}
public int getCount() {
return drawableArray.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
// how to convert string url to imageview?
imageView = new ImageButton(mContext);
imageView.setId(position);
imageView.setLayoutParams(new GridView.LayoutParams(200, 250));
return imageView;
}
}
这个很简单,使用picaso libhttp://square.github.io/picasso/
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
我是 Android 的新手,我需要一些帮助我想通过向 imageAdapter 发送一个字符串数组 url 来设置一个带有 3 个图像按钮的 gridview,我首先使用 urls 来自网络服务 ans 将它们返回到我的片段 class,其中放置了 gridview。 arraylist 由具有 url 字符串集的对象组成。我不知道如何用这些 url 加载 gridview,我应该将它们转换为可绘制对象吗?我看到一些关于使用 asynchtask 的帖子?有人可以帮我吗?我实际上需要图像按钮,或者我可以将点击侦听器连接到图像视图吗?
下载 urls 表单 webservice
后,在片段 class 中启动方法@Override
public void updateScreenMovies(ArrayList<Movie> movies) {
gvNieuw.setAdapter(new ImageAdapter(getActivity(),movies));
}
ImageAdapter class:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Movie> movies;
Drawable[] drawableArray = new Drawable[3];
public ImageAdapter(Context c, ArrayList<Movie> movies) {
mContext = c;
this.movies = movies;
}
public int getCount() {
return drawableArray.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
// how to convert string url to imageview?
imageView = new ImageButton(mContext);
imageView.setId(position);
imageView.setLayoutParams(new GridView.LayoutParams(200, 250));
return imageView;
}
}
这个很简单,使用picaso libhttp://square.github.io/picasso/
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);