Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

On click listener on the text lable #121

Closed
kirill-kostenetskyi opened this issue Sep 9, 2015 · 11 comments
Closed

On click listener on the text lable #121

kirill-kostenetskyi opened this issue Sep 9, 2015 · 11 comments

Comments

@kirill-kostenetskyi
Copy link

Hi. How can i add onClickListner to text label in action menu item?
i can setOnClickListener to ActionMenu value, but in this case it can only responds when i pressing on icon.
Thank you.

@Clans
Copy link
Owner

Clans commented Sep 10, 2015

Just set yout OnClickListener on FAB inside the menu and label will also become clickable.

@kirill-kostenetskyi
Copy link
Author

Can u explain more detailed ?
Look, this is how i create listner:
FloatingActionButton actionMenu = new FloatingActionButton(getApplicationContext());
actionMenu.setOnClickListener(new View.OnClickListener(){...}
Where i need to set listner to do label clicable ?

@Clans
Copy link
Owner

Clans commented Sep 11, 2015

Labels are enabled only if the FAB is placed inside the FAM.

@jzeferino
Copy link
Contributor

I've already added the OnClickListener inside the menu and the label keeps unresponsive to click.

@kirill-kostenetskyi
Copy link
Author

Me too, my FAB placed iside te FAM

@Clans
Copy link
Owner

Clans commented Sep 20, 2015

Please paste your code here so I could look at it.

@jzeferino
Copy link
Contributor

This happens to me only if the FAB is added programmaticlly. When added in XML it works.

@Clans
Copy link
Owner

Clans commented Sep 24, 2015

There's an example of how to add FAB programmatically. Please look at the sample's module code.

@jzeferino
Copy link
Contributor

i'm doing like this:

for (final Sport sport : Sport.values()) {
   FloatingActionButton fab = new FloatingActionButton(getActivity());
   fab.setImageResource(sport.getResource());
   fab.setLabelText(getString(sport.getName()));

   fab.setColorNormal(ContextCompat.getColor(getActivity(), R.color.accent));
   fab.setColorRipple(ContextCompat.getColor(getActivity(), R.color.primary_dark));
   fab.setColorPressed(ContextCompat.getColor(getActivity(), R.color.primary_dark));
   fab.setButtonSize(FloatingActionButton.SIZE_MINI);
   fab.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           createNewChallenge(sport);
       }
   });
   mFabMenu.addMenuButton(fab);
}

@Clans
Copy link
Owner

Clans commented Oct 2, 2015

Thanks! Will fix this in the next build. For now set your OnClickListener after you have added the FAB into the FAM.

@odyodyodys
Copy link

This is not fixed.
While the label is now clickable, it triggers the event with the label's view as an argument, and not the fab's view and you can't use it since its not possible to relate it to its fab.

If you use the code from @jzeferino's comment the bug is there.
A workaround using version 1.6.4 is to:

  • create the button instance
  • add the button to the menu and
  • then add the listener (should be last)

This bug is result of the workflow of it. The logic should be to create, configure and then attach it. Not create, attach and then configure. One good and permanent solution could be to use the builder pattern for adding menu items.

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

No branches or pull requests

4 participants