Skip to content
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

Closed
samuelmgalan opened this issue Feb 16, 2015 · 7 comments
Closed

onTouchEvent to handle onClickListener #5

samuelmgalan opened this issue Feb 16, 2015 · 7 comments

Comments

@samuelmgalan
Copy link

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!

@vbaidak
Copy link
Member

vbaidak commented Feb 16, 2015

Hi samuelmgalan,

  1. Try this one to handle onTouchEvent call:
@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
2. FloatingActionButton extends directly the android.view.View class, so it can't be casted to android.widget.Button class

@vbaidak
Copy link
Member

vbaidak commented Feb 16, 2015

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

@samuelmgalan
Copy link
Author

Thanks for your examples.

My problem is that onTouchEvent() cannot be overriden inside a Fragment, but that's another problem.

Thanks again!

@vbaidak
Copy link
Member

vbaidak commented Feb 16, 2015

What about setting the click listener to this button? Did you manage to make it work?

@samuelmgalan
Copy link
Author

It doesn't work. Never gets called and I think it should be, but i have no idea why not.

@vbaidak
Copy link
Member

vbaidak commented Feb 16, 2015

Could you please send me the code here:
com.software.shell@gmail.com

I'll try to help

@vbaidak
Copy link
Member

vbaidak commented Feb 16, 2015

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 #5 .


Reply to this email directly or view it on GitHub #5 (comment) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants