Why are many OnTouchListeners being initialized at once?

59 views Asked by At

I have the following line of code:

convertView.setOnTouchListener(new ListListener(viewHolder, position));

and the following corresponding block:

private class ListListener implements View.OnTouchListener {
        public SwipeDetector(ViewHolder h, int p) {
            Log.d("ListAdapter", "New ListAdapter listener Created.");
            holder = h;
            position = p;
        }
        public boolean onTouch(View view, MotionEvent motionEvent) {
            Log.d("ListAdapter", "new motionEvent.");
        }
}

When I touch the screen, I get hundreds of logs saying "New ListAdapter listener Created." Yet, despite the fact that it seems like many are being created, only one seems to be handling the onTouch, as expected. Why are so many listeners being created? Should I therefore keep any intensive logic out of the constructor?

0

There are 0 answers