Good day, everyone, I can't figure out how to implement the onTouche method. There is a ScreenPager object inherited from a ViewPager object, scrolling works fine, but there is a row of TextView horizontally, which display the number of pictures, and are colored gray, the textview displays the current picture by coloring itself white. For the color of the textView, I set the onTouchListener event to the ScreenPager object
Код: Выделить всё
View.OnTouchListener touchListenerRelativeHelper = new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
x1 = event.getX();
y1 = event.getY();
}else if (event.getAction() == MotionEvent.ACTION_UP){
x2 = event.getX();
y2 = event.getY();
if (x1 < x2 | x1 > x2 | y1 < y2 | y1 > y2){
int current = screenPagerHelper.getCurrentItem();
for (int i = 0; i < pageTextView.length; i++){
pageTextView[i].setTextColor(android.graphics.Color.GRAY);
}
pageTextView[current].setTextColor(getResources().getColor(R.color.white));
}
}
return false;
}
};
as a result I have a lag in the color of the textView, i.e. if the second picture then the first textView is white, if the third picture is the second, etc. I tried to hang this event on the parent of ScreenPager, relativeLayout, but it doesn't work, I don't know how to make the ScreenPager work first and then the ancestor event fires. If OnTouch returns true then ScreenPager does not work, the event is overridden. Can someone tell me how you can implement it?