1

Hey guys I am parsing data from net and showing the images in grid When the activity is launched only 10 images come from the server and are shown in grid with 3 images in one row. I want to load more images when the user scrolls down and reaches the row where there is only one image

There is a method onScrollChanged(int l, int t, int oldl, int oldt) which i have used earlier to make custom listView

But in this case i dont know how to use it

abhishek
  • 1,434
  • 7
  • 39
  • 71

2 Answers2

5

One way to do this is to detect it in your adapter's getView method. You can check to see if the position parameter refers to the last one you have loaded.

Matthew
  • 44,826
  • 10
  • 98
  • 87
  • but like this i have 10 XML api where i have to send request. I dont want to load the application and put it in never ending state so i need a scroll reached bottom like event i.e. load images only when the list has reached the end or scroll has reached the end – abhishek Mar 18 '11 at 14:31
  • getView will only be called when the view is actually seen on the screen. – Matthew Mar 18 '11 at 14:41
  • public View getView(int position, View convertView, ViewGroup parent) { final int p = position; final ImageView imageView; // if (convertView == null) { // if it's not recycled, initialize some attributes imageView = new ImageView(mContext); int size = (screenWidth * 70) / 240; imageView.setLayoutParams(new GridView.LayoutParams(size, size)); imageView.setImageResource(R.drawable.placeholder); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(8, 8, 8, 8); if(p==(getCount()-1)){ Toast.makeText(wIA, "reached bottom", Toast.LENGTH_SHORT).show();} – abhishek Mar 18 '11 at 21:06
0

I haven't actually tried this, but I suspect what you want is similar to an auto grow listview. Check out the answer to Autogrow ListView in Android

The GridView uses a ListAdapter, so you should be able to use the EndlessAdapter mentioned. BTW, this is basically what @Matthew Willis is talking about.

Community
  • 1
  • 1
slund
  • 6,367
  • 2
  • 26
  • 19
  • ya thanks slund and mathew willis now i have used getView and i am able to print in log but now my problem is that images are not being added below instead they are being replaced and since the last imageview of the grid is visible without scroll also so the images are getting replaced say every 3 seconds lol... – abhishek Mar 19 '11 at 07:36
  • It keeps on setting adapter again and again and replaces the existing 10 images with new images – abhishek Mar 19 '11 at 07:42