Closed samuelmgalan closed 9 years ago
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: com.software.shell@gmail.com
I'll try to help
great
From: samuelmgalan [mailto:notifications@github.com] Sent: Monday, February 16, 2015 2:32 PM To: shell-software/fab Cc: Shell Software Subject: Re: [fab] onTouchEvent to handle onClickListener (#5)
Closed #5 https://github.com/shell-software/fab/issues/5 .
— Reply to this email directly or view it on GitHub https://github.com/shell-software/fab/issues/5#event-236286527 .
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!