Reputation: 11
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv_images;
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.imageadapter1, null);
iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);
iv_images.setImageResource(images[position]);
return convertView;
}
java.lang.OutOfMemoryError: Failed to allocate a 9042060 byte allocation with 8030424 free bytes and 7MB until OOM
Upvotes: 0
Views: 102
Reputation: 532
You can use libraries such as Picasso
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv_images;
final LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.imageadapter1, null);
iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);
Picasso.get()
.load(images[position])
.resize(YOUR_WIDTH, YOUR_HEIGHT)
.centerCrop()
.into(iv_images)
return convertView;
}
Don't forgot to add dependecies.
Gradle:
implementation 'com.squareup.picasso:picasso:2.71828'
Maven:
<dependency>
<groupId>com.squareup.picasso</groupId>
<artifactId>picasso</artifactId>
<version>2.71828</version>
</dependency>
Upvotes: 0
Reputation: 464
You could just use a smaller image.
You may, try this link https://developer.android.com/topic/performance/graphics/load-bitmap
Upvotes: 1