I am using OnOffsetChangedListener interface to detect AppBarLayout's offset change. It working fine but the problem is onOffsetChanged method is calling continuously. How can i stop this continuous call.
offsetChangedListener = (appBarLayout, verticalOffset) -> {
Log.i(TAG, "onOffsetChanged: verticalOffset: " + verticalOffset);
// Vertical offset == 0 indicates appBar is fully expanded.
if (Math.abs(verticalOffset) > 200) {
appBarExpanded = false;
invalidateOptionsMenu();
} else {
appBarExpanded = true;
invalidateOptionsMenu();
}
};
Thanks in advance.
Got the cause of the problem. Every time AppBarLayout's offset change that code is calling invalidateOptionsMenu() method. This invalidateOptionsMenu() method recreate Menu and cause AppBarLayout's offset change. So onOffsetChanged method is called again and again. I have removed invalidateOptionsMenu() method and change my logic to achieve my goal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With