-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onTouchEvent to handle onClickListener #5
Comments
Hi samuelmgalan,
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
// Your code goes here
return true; // if handled, otherwise false
} So you just need to call super.onTouchEvent(event) and return true if your button click is handled, otherwise false |
Here is how it is done in sample: Declaration inside XML: <com.software.shell.fab.FloatingActionButton
android:id="@+id/fab_activity_action_button"
style="@style/fab_action_button_style"
android:onClick="onActionButtonClick"
fab:type="DEFAULT"
/> and then onActionButtonClick method in code: public void onActionButtonClick(View v) {
if (hideAndShowOnClickCheckBox.isChecked()) {
actionButton.hide();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
actionButton.show();
}
}, ACTION_BUTTON_SHOW_DELAY_MS);
}
} I will provide the full demo sample a bit later today |
Thanks for your examples. My problem is that onTouchEvent() cannot be overriden inside a Fragment, but that's another problem. Thanks again! |
What about setting the click listener to this button? Did you manage to make it work? |
It doesn't work. Never gets called and I think it should be, but i have no idea why not. |
Could you please send me the code here: I'll try to help |
great From: samuelmgalan [mailto:notifications@github.com] — |
Hi.
How is onTouchEvent supposed to work? I can't find the correct way to handle onClick events. I've tried setOnClickListener and setOnTouchListener without luck. And I can't cast FloatingActionButton to Button because it gives an error.
Can you provide an example? Thanks!
The text was updated successfully, but these errors were encountered: