Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overriding the onScroll method of the com.android.View in android coding?

Tags:

java

android

view

How can I override the onScroll method of the View in android? I using it for the view to prevent the update in the view's checkboxes while when I scroll. I use a two dimensional array for storing the values of the checkbox's.

I use the following but did not work for me.

public void onScroll(View view, int firstItem, int visibleItemCount, int totalItemCount { 
    // here i check the view's check box 
    checkBox1.setchecked(true);
}
like image 514
hanif s Avatar asked May 22 '13 07:05

hanif s


1 Answers

You cannot. If you with to override a method supplied in an API class you will have to extend that class. I would suggest implementing your own custom View and override the onScroll method.

public class YourCustomView extends View
{
    @Override
    public void onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    {
        /** Whatever you need to do, do it here! */
    }
}

However, I do not find this the best way to handle the situation. I would suggest using a ViewHolder. Basically, it is a container that holds information about your View's items. I would recommend using it, especially if you have a list or multiple items to handle. You can read all about here in this question!

like image 179
Eric Tobias Avatar answered Oct 20 '22 20:10

Eric Tobias