0

I implemented a Float Action button, which has 5 sub-action button using the code below, how can I add a onClickListener to each of this sub-action buttons so that when you click is should open different activity.

 SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    ImageView rlIcon4 = new ImageView(this);
    ImageView rlIcon5 = new ImageView(this);
    //ImageView rlIcon6 = new ImageView(this);

     rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_contact));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_currency_info));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_exhibition));
    rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_faq));
    rlIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_info_desk));
    //rlIcon6.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_passport));



    // Build the menu with default options: light theme, 90 degrees, 72dp radius.
    // Set 4 default SubActionButtons
    final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this)
            .addSubActionView(rLSubBuilder.setContentView(rlIcon1).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon2).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon3).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon4).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon5).build())
            //.addSubActionView(rLSubBuilder.setContentView(rlIcon6).build())
            .attachTo(rightLowerButton)
            .build();

    // Listen menu open and close events to animate the button content view
    rightLowerMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {
        @Override
        public void onMenuOpened(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees clockwise
            fabIconNew.setRotation(0);
            PropertyValuesHolder pvhR =  PropertyValuesHolder.ofFloat(View.ROTATION, 90);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }

        @Override
        public void onMenuClosed(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees counter-clockwise
            fabIconNew.setRotation(90);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
            ObjectAnimator animation =  ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }
    });

}
Omega
  • 289
  • 1
  • 4
  • 14

2 Answers2

1

Try to:

SubActionButton button1 = rLSubBuilder.setContentView(rlIcon1).build();
SubActionButton button2 = rLSubBuilder.setContentView(rlIcon2).build();
[...]
SubActionButton buttonN = {...}

button1.setOnClickListener(...);
button2.setOnClickListener(...);
[...]

 final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this)
            .addSubActionView(button1)
            .addSubActionView(button2)
            .addSubActionView(rLSubBuilder.setContentView(rlIcon3).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon4).build())
            .addSubActionView(rLSubBuilder.setContentView(rlIcon5).build())
            //.addSubActionView(rLSubBuilder.setContentView(rlIcon6).build())
            .attachTo(rightLowerButton)
            .build();
dieter_h
  • 2,707
  • 1
  • 13
  • 19
0

I'm assuming that you're using this library. Looking at the source you can see that setContentView just adds the view to the CircularActionMenu which is derived from a FrameLayout. Hence setting onClickListeners to your ImageViews to open new activities should do it. This is what your onClickListeners should look like

rIIcon1.setOnClickListener(new View.OnCLickListener(){
    @Override
    public void onClick(View view){
       Intent intent = new Intent(getApplicationContext(),ActivityName.class)
       startActivity(intent)
    }
})

Similarly attach listeners to the other imageviews

ashkhn
  • 1,642
  • 1
  • 13
  • 18
  • yes you are right, but am a rookie, how do I set onClickListeners to my ImageViews. I will appreciate an edit on my code – Omega Oct 18 '15 at 17:57