This one is my first post on any forum, so apologies for any incorrect format. I am using this custom adapter to get images in listView and it loads those images at once, but I want to load those images one by one scrolling and remove the previous image which is no longer available on the screen after scrolling. thanks for any relevant solution in advance.
class MyAdapter extends BaseAdapter {
private Context context;
private int images[];
public MyAdapter(Context context, int images[]) {
this.context = context;
this.images = images;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return images[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
class MyViewHolder {
ImageView imageView;
public MyViewHolder(View v) {
// TODO Auto-generated constructor stub
imageView = (ImageView) v.findViewById(R.id.imgView);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
MyViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.custom_list, parent, false);
holder = new MyViewHolder(row);
row.setTag(holder);
} else {
holder = (MyViewHolder) row.getTag();
}
holder.imageView.setImageResource(images[position]);
return row;
}
}
and here is my MainActivity where I am calling MyAdapter to get that list of images, currently I am calling MyAdapter to get listview of 50 images, but I'll be calling this for 500 images soon.
private ListView listView;
private MyAdapter myAdapter;
int[] images = { R.drawable.img001, R.drawable.img002, R.drawable.img003,
R.drawable.img004, R.drawable.img005, R.drawable.img006,
R.drawable.img007, R.drawable.img008, R.drawable.img009,
R.drawable.img010, R.drawable.img011, R.drawable.img012,
R.drawable.img013, R.drawable.img014, R.drawable.img015,
R.drawable.img016, R.drawable.img017, R.drawable.img018,
R.drawable.img019, R.drawable.img020, R.drawable.img021,
R.drawable.img022, R.drawable.img023, R.drawable.img024,
R.drawable.img025, R.drawable.img026, R.drawable.img027,
R.drawable.img028, R.drawable.img029, R.drawable.img030,
R.drawable.img031, R.drawable.img032, R.drawable.img033,
R.drawable.img034, R.drawable.img035, R.drawable.img036,
R.drawable.img037, R.drawable.img038, R.drawable.img039,
R.drawable.img040, R.drawable.img041, R.drawable.img042,
R.drawable.img043, R.drawable.img044, R.drawable.img045,
R.drawable.img046, R.drawable.img047, R.drawable.img048,
R.drawable.img049, R.drawable.img050 };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myAdapter = new MyAdapter(this, images);
listView = (ListView) findViewById(R.id.imgList);
listView.setAdapter(myAdapter);
}