1
Hello! I found a lib of a float action with speed dial and I’m trying to implement it in my Android project, but I’m not able to interact with the Float Button...
follows the code of the fragment containing the 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();
}
}
the XML of this fragment:
<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>
The menu file:
<?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>
The Guide to the LIB: https://github.com/yavski/fab-speed-dial
I keep having the same problem =\
– Mikhael Araujo