0

I'm trying to change the visibility of the RecyclerView to View.GONE. However, no changes are taking place:

@Override
public boolean onQueryTextSubmit(String query) {
      runOnUiThread(new Runnable() {
           @Override
            public void run() {
               list.setVisibility(View.GONE);
                }
            });
      if (list == null){
        throw new NullPointerException();
      }

Here's the View:

<android.support.v7.widget.RecyclerView
            android:id="@+id/allUsers"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/toolbar_container" />

Removing runOnUiThread doesn't work, nor does list.invalidate(). Nothing is crashing. This is in an inner class. What am I doing wrong?

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117

1 Answers1

0

Turns out that when you access a variable from an inner class, the compiler should say:

Variable 'x' is accessed from an inner class, needs to be declared final

For some reason I wasn't getting the comile-time error. Even though the variable was declared in a method.

So make sure the variable you're accessing from the inner class is declared final like this:

final X y;

and not like this:

X y;

Where X is the type and y is the name of the variable.

See Why are only final variables accessible in anonymous class?

Community
  • 1
  • 1
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
  • The variable doesn't need to be final if it's in the scope of the class which is seems to be here. – DeeV Dec 05 '16 at 15:40