title: How to return a value from a method that needs to perform some operations inside a Runnable?
body: <p>To get the width of a view when the Activity/Fragment is still measuring its views, you use a <code>ViewTreeObserver</code> or  the View's post method with your own <code>Runnable</code>. I usually adopt de second one. But now -after some calculations, I would like to return the value, but because the method <code>run</code> doesn’t return any value (<code>void</code>), and I must way to measure the width of the view, I have come to a dead end. Has someone any idea?</p>
  
  <p>Thanks!</p>
  
  <pre><code>int getDesiredWidth(final View view) {
      final int[]finalWidth = {0};
  
      view.post(new Runnable() {
          @Override
          public void run() {
              int width = view.getLayoutParams().width;
              //Calculate 'finalWidth' computing margins and other size's view
              return finalWidth[0]; //error: cannot return a value from a method with void type
          }
      });
  
      return finalWidth[0];
  }
  </code></pre>