Я создаю приложение, которое динамически загружает изображения из сценария и отображает их в виде сетки.setImageResource in android
Вот код.
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.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;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private String[] mThumbIds = new String[]{
"http://localhost/comic_app/index.php?id=1",
"http://localhost/comic_app/index.php?id=67",
"http://localhost/comic_app/index.php?id=4",
"http://localhost/comic_app/index.php?id=89",
"http://localhost/comic_app/index.php?id=98",
"http://localhost/comic_app/index.php?id=23",
"http://localhost/comic_app/index.php?id=45",
};
}
Я получаю ошибку компиляции времени на
imageView.setImageResource(mThumbIds[position]);
Error: cannot be applied to (java.lang.String)
Я знаю setImageResource хочет получить ИНТ, но как это сделать. Заранее спасибо
ответ конвертировать в растровое изображение, а затем setImageReource –
вместо setImageReource() используют библиотеку Пикасо, чтобы загрузить изображение из url, другой мудрый вы хорошо получаете outOfMemory исключение. Проверьте это: http: //square.github.io/picasso/ –
вы не можете использовать локальный URL-адрес хоста в приложении. –