1

Olá! Encontrei uma lib de um float action com speed dial e estou tentando implementa-la no meu projeto Android, mas não estou conseguindo interagir com o Float Button...

segue o código do fragmento que contém o float:

public class NovaPesquisaFragment extends Fragment {

private AlertDialog.Builder dialogBuilder;
AlertDialog dialog;
private ArrayList<PerguntasModel> perguntas;
private CardView cardDinamicoPergunta;
private RecyclerView recyclerView;
private FirebaseAuth mAuth;
private FirebaseUser user;
private DatabaseReference fbDatabaseRef, fbUserDatabaseRef;
private FirebaseFirestore fbCloudStore;
private Listener listener;
private int i;
private View rootView;
private AdapterPerguntas adapterPerguntas;
private FabSpeedDial floatSpeelDial;

public NovaPesquisaFragment() {
}

public interface Listener{
    public DatabaseReference getdatabaseRef();
    public FirebaseDatabase getfbDatabase();
    public FirebaseAuth getmAuth();
    public FirebaseAuth.AuthStateListener getmAuthListener();
    public FirebaseUser getUser();
    public FirebaseFirestore getFbCloudStore();
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null){
        i = savedInstanceState.getInt("i");
    }else{
        i = 0;
    }
}

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_nova_pesquisa, container, false);
    variaveisDoXML();
    return rootView;
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("i", i);
}


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    pegarFirebaseListener();

    recyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
    final AdapterPerguntas adapterPerguntas = new AdapterPerguntas();
    recyclerView.setAdapter(adapterPerguntas);

    dialogBuilder = new AlertDialog.Builder(getContext());
    perguntas = new ArrayList<>();

    floatSpeelDial.setMenuListener(new SimpleMenuListenerAdapter(){
        @Override
        public boolean onPrepareMenu(NavigationMenu navigationMenu){
            return true;
        }
        public boolean onMenuItemSelected(MenuItem menuItem){
            switch (menuItem.getItemId()){
                case R.id.menuSpeedDial_action_call:
                    Toasty.info(getContext(),"item 1", Toast.LENGTH_LONG).show();
                    break;
            }
            return true;
        }
    });
}

private void variaveisDoXML() {

    floatSpeelDial = (FabSpeedDial) rootView.findViewById(R.id.floatSpeelDial);
    cardDinamicoPergunta = (CardView) rootView.findViewById(R.id.cardView_dinamico_pergunta);
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView_perguntas);

}

private void criarDialogo(View view, Boolean canceleable, Boolean canceleableTouch){
    dialogBuilder.setView(view);
    dialog = dialogBuilder.create();
    dialog.setCancelable(canceleable);
    dialog.setCanceledOnTouchOutside(canceleableTouch);
    dialog.show();
}

private void pegarFirebaseListener(){
    listener = (Listener) getActivity();
    mAuth = listener.getmAuth();
    fbDatabaseRef = listener.getdatabaseRef();
    user = listener.getUser();
    fbCloudStore = listener.getFbCloudStore();
    fbUserDatabaseRef = fbDatabaseRef.child(user.getUid());
}

@Override
public void onPause() {
    super.onPause();

}

@Override
public void onResume(){
    super.onResume();
}
}

o XML desse fragmento:

<android.support.v7.widget.CardView
    android:id="@+id/cardView_dinamico_pergunta"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginTop="8dp"
    android:elevation="5dp"
    android:focusableInTouchMode="true"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="5dp"
    app:cardUseCompatPadding="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <io.github.yavski.fabspeeddial.FabSpeedDial
        android:id="@+id/floatSpeelDial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:fabGravity="bottom_end"
        app:fabMenu="@menu/speeldial_menu"
        app:miniFabBackgroundTint="@android:color/white"
        app:miniFabDrawableTint="?attr/colorPrimaryDark"
        app:miniFabTitleTextColor="?attr/colorPrimaryDark" />

    <android.support.v7.widget.RecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/recyclerView_perguntas"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        app:shimmer_demo_angle="10"
        app:shimmer_demo_child_count="5"
        app:shimmer_demo_grid_child_count="1"
        app:shimmer_demo_layout="@layout/layout_demo_grid"
        app:shimmer_demo_layout_manager_type="linear_horizontal">

    </android.support.v7.widget.RecyclerView>

</android.support.v7.widget.CardView>

O arquivo do menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menuSpeedDial_action_call"
        android:icon="@drawable/icon_account"
        android:title="menu call" />

</menu>

O guia da LIB: https://github.com/yavski/fab-speed-dial

1 Resposta 1

0

Me parece que no método onPrepareMenu você está retornando false, com isso dizendo para a library não exibir os itens.

Events

As with all menus, you have a callback just before the list of actionable items are presented. The callback allows you to update your menu items, or not show the menu altogether.

FabSpeedDial fabSpeedDial = (FabSpeedDial) findViewById(R.id.fab_speed_dial);
        fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
            @Override
            public boolean onPrepareMenu(NavigationMenu navigationMenu) {
                // TODO: Do something with yout menu items, or return false if you don't want to show them
                return true;
            }
        });
1
  • Continuo tendo o mesmo problema =\ Commented 14/11/2017 às 13:39

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .