Scrollview listener not working in Xamarin for Android?

I use for C # in Xamarin to create an Android application. I created the scrollview extension. Here is my code for this

public class EndlessScroll : ScrollView
{ 
    public EndlessScroll (Context context) : base (context)
    {

    }

    public EndlessScroll(Context context, IAttributeSet attrs) : base(context, attrs)
    {



    }

    public EndlessScroll(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {

    }



    public interface OnScrollViewListener
    {
        void onScrollChanged(EndlessScroll v, int l, int t, int oldl, int oldt);
    }

    public  OnScrollViewListener scrollViewListener;

    public void setOnScrollViewListener(OnScrollViewListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }


    protected   void onScrollChanged(int l, int t, int oldl, int oldt)
    {

        base.OnScrollChanged(l, t, oldl, oldt);
        if (scrollViewListener != null) {
            scrollViewListener.onScrollChanged(this, l, t, oldl, oldt);
          }

    }


}

}

I tried to implement it in another class. I don't get compilation errors, but it doesn't register when scrollview hit the bottom. Here is the code I have.

public class getFromParse:Activity, EndlessScroll.OnScrollViewListener {

    LinearLayout linear; 
    Button buttonSort; 
    Typeface font; 


protected override void OnCreate (Bundle bundle)
    {
        Window.RequestFeature(WindowFeatures.NoTitle);
        base.OnCreate (bundle); 
        SetContentView (Resource.Layout.debugLog);



   EndlessScroll  scroll = FindViewById <EndlessScroll> (Resource.Id.scrollView); 
        scroll.setOnScrollViewListener (this); 

And this is where the scroll view listener should detect when it hits the bottom.

public  void onScrollChanged(EndlessScroll scrollView, int x, int y, int oldx, int oldy) {
        // We take the last son in the scrollview
        View view = (View) scrollView.GetChildAt(scrollView.ChildCount  - 1);
        int diff = (view.Bottom  - (scrollView.Height + scrollView.ScrollY));

        // if diff is zero, then the bottom has been reached
        if (diff == 0) {
            Console.WriteLine ("Scroll changed"); 
        }
    }

If anyone can help me and tell me what I'm doing wrong, that will be a big help. It seems like I'm doing everything right, but maybe I'm missing something.

+4
source share
1 answer

, . , - , # Xamarin, .

public class EndlessScroll : ScrollView
{ 
    private ScrollViewListener scrollViewListener = null; 
    public EndlessScroll (Context context) : base (context) 
    {

    }
    public EndlessScroll(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
    {

    }

    public EndlessScroll(Context context, IAttributeSet attrs) : base(context, attrs)
    {



    }




    public interface ScrollViewListener
    {
        void OnScrollChanged(EndlessScroll v, int l, int t, int oldl, int oldt);
    }



    public void setOnScrollViewListener(ScrollViewListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }


    protected override void OnScrollChanged(int l, int t, int oldl, int oldt)
    {


        base.OnScrollChanged (l, t, oldl, oldt); 
        if (scrollViewListener != null) {
            scrollViewListener.OnScrollChanged (this, l, t, oldl, oldt);
        } 
    }


}

, OnScrollChanged.

, , . oncreate.

 EndlessScroll  scroll = FindViewById <EndlessScroll> (Resource.Id.scrollView); 


        scroll.setOnScrollViewListener (this); 

, .

public void  OnScrollChanged(EndlessScroll scrollView, int l, int t, int oldl, int oldt) {
        // We take the last son in the scrollview
        View view = (View) scrollView.GetChildAt(scrollView.ChildCount  - 1);
        int diff = (view.Bottom  - (scrollView.Height + scrollView.ScrollY));

        // if diff is zero, then the bottom has been reached
        if (diff <= 0 && myResources.isLoading == false) {
            myResources.isLoading = true; 
           //do stuff here 
        }


    }

, , , .

+7

All Articles