Java – How to set up OnClickListener (Android)

How to set up OnClickListener (Android)… here is a solution to the problem.

How to set up OnClickListener (Android)

I

know this is a very simple and even silly question, but I can’t set up OnClickListener for my float action buttons. I’ve never made one for myself that didn’t make a button (using the library) and I just need some help. This is the code I’m using: https://gist.github.com/VirusThePanda/20320afd303150c02ea5

Here is the library I use for the

buttons, and the source code I use for the navigation bar. This might come in handy because it has a placeholder fragment that can be attached to the main activity.

Source: android-toolbar-with-drawer (from GitHub)
Library: android-floating-action-button (from GitHub).

Once again, I apologize for this very simple question. I’m still learning Java and XML. Thanks for your help 🙂

Solution

Try this :

<com.getbase.floatingactionbutton.FloatingActionsMenu
        android:id="@+id/multiple_actions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:onClick="fabClicked"
        fab:fab_addButtonColorNormal="#ec407a"
        fab:fab_addButtonColorPressed="#d81b60"
        fab:fab_labelStyle="@style/menu_labels_style"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"/>

Then, in your Activity file (that is, in class custom_motivation), define the function fabClicked as:

...
public void fabClicked(View v){
   write your code here ..
}
...

Related Problems and Solutions