How to call Activity/Fragment when clicking the button? Android Studio

Asked

Viewed 1,216 times

0

I’m starting a short time with programming, I’ve researched a lot but I need help in this doubt

I will use a menu in my app called Boom Menu https://github.com/Nightonke/BoomMenu

My question is, where do I put the reference to call Activity when clicking the button?

I’ve searched the entire library, and I have no idea

Has anyone used or knows where it puts?

I chose this code button style below:

Easeactivity.java

package com.nightonke.boommenusample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.nightonke.boommenu.BoomMenuButton;

public class EaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ease);

        initBmb(R.id.bmb4);

    }

    private BoomMenuButton initBmb(int res) {
        BoomMenuButton bmb = (BoomMenuButton) findViewById(res);
        assert bmb != null;
        for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++)
            bmb.addBuilder(BuilderManager.getSimpleCircleButtonBuilder());
        return bmb;
    }
}

activity_ease.xml

<com.nightonke.boommenu.BoomMenuButton
    android:id="@+id/bmb4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    app:bmb_normalColor="@android:color/holo_green_light"
    app:bmb_highlightedColor="@android:color/holo_green_dark"
    app:bmb_buttonEnum="simpleCircle"
    app:bmb_piecePlaceEnum="piecePlace_dot_9_1"
    app:bmb_buttonPlaceEnum="buttonPlace_sc_9_1"
    app:bmb_showMoveEaseEnum="outElastic"
    app:bmb_showScaleEaseEnum="outElastic"
    app:bmb_showRotateEaseEnum="outElastic"
    app:bmb_hideMoveEaseEnum="inElastic"
    app:bmb_hideScaleEaseEnum="inElastic"
    app:bmb_hideRotateEaseEnum="inElastic"
    app:bmb_showDelay="0"
    app:bmb_hideDelay="0"
    />

2 answers

1

I think it’s simpler that way.

public void abrirActivity(View v){
    Intent intent = new Intent(this,MinhaActivityQuevaiAbrir.class);
    startActivity(intent);
}

Remember that in the attribute of your button you should put in the onclick your method open Active. Attributes is on the right side of Android Studio. inserir a descrição da imagem aqui

  • Stênio, the button is only one, but it opens 6 more buttons, if I do it your way, will only open an Activity? There is another way to do it?

  • I saw the link you passed, you want to call several buttons by the floating button of Activity. What I understood is that you wanted to call an Activity. Something else you already downloaded the link example.

0

Good night, Michael!

Generally, you should reference your Views in the method onCreate of his Activity. In the case of the library, you can use it as follows

Get your View, the button, and tell your type

public class EaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ease);

        BoomMenuButton bmb = (BoomMenuButton) findViewById(res);
                       // Isso define o tipo do botão
                       bmb.setButtonEnum(ButtonEnum.SimpleCircle);
                       bmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_3_1);

    }
}

Now, according to the documentation, you should add the "extension buttons"

public class EaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ease);

        BoomMenuButton bmb = (BoomMenuButton) findViewById(res);
                       // Isso define o tipo do botão
                       bmb.setButtonEnum(ButtonEnum.SimpleCircle);
                       bmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_3_1);

       for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++) {
            SimpleCircleButton.Builder builder = new SimpleCircleButton.Builder()
               .normalImageRes(R.drawable.jellyfish); // Você pode setar para cada no sub-botão um ícone diferente

            bmb.addBuilder(builder);
       }
    }
}

Finally, you’ll probably want to know when any of the buttons are clicked, so just attach the click event

public class EaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ease);

        BoomMenuButton bmb = (BoomMenuButton) findViewById(res);
                       // Isso define o tipo do botão
                       bmb.setButtonEnum(ButtonEnum.SimpleCircle);
                       bmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_3_1);

       for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++) {
            SimpleCircleButton.Builder builder = new SimpleCircleButton.Builder()
               .normalImageRes(R.drawable.jellyfish); // Você pode setar para cada no botão um ícone diferente

            builder.listener(new OnBMClickListener() {
                @Override
                public void onBoomButtonClick(int index) {
                  // Pra saber qual o botão que foi clicado, uso index          
                // Digamos que você queira que o segundo botão de extensão abra outra tela [Activity] e levando em conta que a biblioteca considera o primeiro índice como 0, o segundo será 1
                  if (index == 1) startActivity(new Intent(EaseActivity.this, ActivityDeDestino.class));
                }
            });
            bmb.addBuilder(builder);
       }

      // A documentação não deixa claro, mas acredito que você deve chamar o método build();
      bmb.build();
    }
}
  • Thanks for the explanation! I didn’t understand, now you’ve made a clear, I’ll try again tomorrow. I want to put 6 buttons, and each calling a different Activity, I will try!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.