i have a listview that displays images from a directory and it is loading the images fine but then when scrolling in order to scroll up after scrolling down i have to remove my finger from the screen and place it back on the screen to scroll back up. also if scroll is too fast application crashes with logcat saying OutOfMemoryError.
here is my code:
package com.search.visual;
import java.io.File;
import java.io.FilenameFilter;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
public class history extends ListActivity{
private String dir = ".vis";
private File images;
private File [] imageList;
private File item;
private Uri [] ImageRef;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
loadPics();
}
public class ImageAdapter extends BaseAdapter {
int Background;
private Context con;
public ImageAdapter(Context c) {
con = c;
TypedArray attr = con.obtainStyledAttributes(R.styleable.HelloGallery);
Background = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return ImageRef.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
imageView = new ImageView(con);
imageView.setImageURI(ImageRef[position]);
imageView.setLayoutParams(new ListView.LayoutParams(75, 75));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(Background);
return imageView;
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
item = imageList[position];
Intent i = new Intent("com.search.visual.IMAGE");
i.putExtra(Intent.EXTRA_STREAM, item);
startActivity(i); //StIntring imname = (String) ;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
loadPics();
super.onResume();
}
public void loadPics(){
images = Environment.getExternalStoragePublicDirectory(dir);
imageList = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
// TODO Auto-generated method stub
return (filename.endsWith(".jpg"));
}
});
if(imageList.length > 0 ){
ImageRef = new Uri[imageList.length];
for(int i = 0; i<imageList.length; i++){
ImageRef[i] = Uri.parse(imageList[i].getAbsolutePath());
}
setListAdapter(new ImageAdapter(this));
}else{
Intent i = new Intent("com.search.visual.ERROR");
startActivity(i);
}
}
}
if anyone one has any clue as to why this is happening your help would be greatly appreciated