1

What I'm trying to here is to hide the FAB and the text whenever results returns an empty value/string. Methods hideTextView() and setText() are working fine but the FAB are still always being shown whether it returns an empty string or not.

   if (args.getString("results").isEmpty()) {
        activity.hideTextView(text);
        activity.hideButton(fabButton);
    } else {
        activity.setText(text, args.getString("text"));
        activity.showButton(fabButton);

Below are the methods I used for showing/hiding the TextViews and the FAB. I've also tried floatingActionButton.hide() and floatingActionButton.show() but it's still not working

 public void hideButton(final FloatingActionButton floatingActionButton) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                floatingActionButton.setVisibility(View.GONE);
                //floatingActionButton.hide()
            }
        });
    }

    public void showButton(final FloatingActionButton floatingActionButton) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                floatingActionButton.setVisibility(View.VISIBLE);
                //floatingActionButton.show();
            }
        });
    }

 public void hideTextView(final TextView textView) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                textView.setVisibility(View.GONE);
            }
        });
    }

public void setText(final TextView text, final String value) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                text.setText(value);
            }
        });
    }

fab

<android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fabButton"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/cover"
        android:src="@drawable/ic_icon1"
        app:backgroundTint="@color/colorAccent"
        android:clickable="true"
        android:layout_marginRight="210dp"
        android:layout_marginTop="-28dp"
        android:adjustViewBounds="false"/>
BXUMZSE
  • 211
  • 2
  • 11

2 Answers2

0

use floatingActionButton.hide(); instead of floatingActionButton.setVisibility(View.GONE);

floatingActionButton.hide(); // to hide
floatingActionButton.show();// to show
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

It might be due to the app:layout_anchor attribute in your xml code. The anchor must be changed before changing the visibility. Try adding this piece of code inside run:

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) floatingActionButton.getLayoutParams();
p.setAnchorId(View.NO_ID);
floatingActionButton.setLayoutParams(p);
floatingActionButton.setVisibility(View.GONE);
Karun Shrestha
  • 731
  • 7
  • 16