0

I have an ImageView inside a RelativeLayout.It gets images from database.I want to add scroll-event to it such that when image is scrolled I should get next and previous image based on direction of scroll.

How can I do that in android?

Akshay
  • 2,506
  • 4
  • 34
  • 55
user1618951
  • 53
  • 1
  • 1
  • 6
  • 1
    Have you used any listview for displaying images? – Praveenkumar Sep 10 '12 at 05:32
  • Agreed with SpK. [Use a `ListView`](http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview). – Cat Sep 10 '12 at 05:32
  • No , i m directly using imageview.So I should use a listview inside the relativelayout? – user1618951 Sep 10 '12 at 05:33
  • 1
    Yes. If you use `ListView` it will be more efficient with as per **Eric**'s suggestion or you can use [onScrollListener](http://benjii.me/2010/08/endless-scrolling-listview-in-android/) for your `ListView` to load more your images from database. – Praveenkumar Sep 10 '12 at 05:35
  • Can u tell me how to implement using onScrollListener? – user1618951 Sep 10 '12 at 05:42

1 Answers1

0

OnScrollListener

  • Interface definition for a callback to be invoked when the list or grid has been scrolled.

Example for implementing the onScrollListner as per below code -

//Here is where the magic happens
this.getListView().setOnScrollListener(new OnScrollListener(){

//useless here, skip!
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {}

//dumdumdum
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
    int visibleItemCount, int totalItemCount) 
    {
        //what is the bottom iten that is visible
        int lastInScreen = firstVisibleItem + visibleItemCount;             

        //is the bottom item visible & not loading more already ? Load more !
        if((lastInScreen == totalItemCount) && !(loadingMore)){
            Thread thread =  new Thread(null, loadMoreListItems);
            thread.start();
        }
    }
});

Have a look at this example and you can also use this Lazy load of images in ListView also

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173