title: Get location on screen for view in view holder
body: <p>I have a Recyclerview that is managed by an adapter. For each item in the recycler I inflate a complex view that contains also a horizontal progressbar which takes the whole width of screen. </p>
  
  <p>I have to position a baloon TextView with the percentage value (20% , 60% etc) that points to the progressbar like an indicator to the amount of progress. I tried using this code</p>
  
  <pre><code>int[] startPosition =  new int[2];
  Integer progresswidth;
  WindowManager wm = (WindowManager) contextthis.getSystemService(Context.WINDOW_SERVICE);
  Display display = wm.getDefaultDisplay();
  Point size = new Point();
  display.getSize(size);
  progresswidth = size.x;
  holder.horiz_progress.getLocationOnScreen(startPosition);
  float exactvalue = (progresswidth * currentitem.getMatchPercent()) / 100;
  startPosition[0] = startPosition[0] + Math.round(exactvalue);
  startPosition[0] = startPosition[0] - holder.baloon_txt.getWidth() / 3 ;
  startPosition[1] = startPosition[1] + 10;
  holder.baloon_txt.setX(startPosition[0]);
  holder.baloon_txt.setY(startPosition[1]);
  </code></pre>
  
  <p>But the problem is that <code>holder.horiz_progress.getLocationOnScreen</code> always returns 0 so I cannot position the <code>balloon_txt</code>. 
  I had a similar issue inside an activity and there i resolved it overriding <code>OnWindowFocusChanged</code> but this is inside the adapter so I don't know how to get it done.</p>
  
  <p>EDIT </p>
  
  <p>My current adapter code:</p>
  
  <pre><code>public class ResultsAdapter extends RecyclerView.Adapter&lt;ResultsAdapter.ViewHolder&gt;{
  
  private List&lt;ResultsItem&gt; mResults;
  private View mSelectedView;
  private int mSelectedPosition;
  Context contextthis;
  android.os.Handler handler;
  int[] startPosition =  new int[2];
  
  public ResultsAdapter(Context context,List&lt;ResultsItem&gt; resultsItemList) {
      this.mResults = resultsItemList;
      contextthis = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.results_item, null);
      final ViewHolder viewHolder = new ViewHolder(v);
  
      viewHolder.results_likeimg.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
          }
      });
  
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder( final ViewHolder holder, int position) {
      final ResultsItem currentitem = mResults.get(position);
      //set Image
      if(currentitem.getImageslist().get(0).getPicture() != null)
          ImageLoader.getInstance().displayImage(currentitem.getImageslist().get(0).getPicture(), holder.results_img);
  
      //baloon set
      holder.baloon_txt.setText(currentitem.getMatchPercent() + "% " + "Match");
      holder.horiz_progress.setProgress(currentitem.getMatchPercent());
      final View view = holder.horiz_progress;
              view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
              view.getLocationOnScreen(startPosition);
              Integer progresswidth;
              WindowManager wm = (WindowManager) contextthis.getSystemService(Context.WINDOW_SERVICE);
              Display display = wm.getDefaultDisplay();
              Point size = new Point();
              display.getSize(size);
              progresswidth = size.x;
              float exactvalue = (progresswidth * currentitem.getMatchPercent()) / 100;
              startPosition[0] = startPosition[0] + Math.round(exactvalue);
              startPosition[0] = startPosition[0] - holder.baloon_txt.getWidth() / 3 ;
              startPosition[1] = startPosition[1] + 10;
              holder.baloon_txt.setX(startPosition[0]);
              holder.baloon_txt.setY(startPosition[1]);
          }
      });
  
  
      //logo
      if(currentitem.getPriceslist().get(0).getSource() != null)
          ImageLoader.getInstance().displayImage(currentitem.getPriceslist().get(0).getSource(), holder.results_logo_img);
  
      //description
      holder.description_txt.setText(currentitem.getDescription());
  
      //price
      holder.price_curr.setText(currentitem.getPriceslist().get(0).getCurrency());
      holder.price_txt.setText(String.valueOf(currentitem.getPriceslist().get(0).getPrice()));
  }
  
  @Override
  public int getItemCount() {
      return mResults.size();
  }
  
  public static class ViewHolder extends RecyclerView.ViewHolder {
  
      ImageView results_img, results_dislikeimg, results_likeimg, results_logo_img;
      ProgressBar horiz_progress;
      TextView baloon_txt, price_txt, description_txt, buybtn, sharebtn, price_curr;
  
      public ViewHolder(View view) {
          super(view);
  
          this.results_img = (ImageView) view.findViewById(R.id.resultsitem_img);
          this.results_dislikeimg = (ImageView) view.findViewById(R.id.results_item_dislike);
          this.results_likeimg = (ImageView) view.findViewById(R.id.resultsitem_like);
          this.results_logo_img = (ImageView) view.findViewById(R.id.logoimg);
          this.horiz_progress = (ProgressBar) view.findViewById(R.id.progressBar_horizontal);
          this.baloon_txt = (TextView) view.findViewById(R.id.baloonMatch_txt);
          this.price_txt = (TextView) view.findViewById(R.id.price_txt);
          this.description_txt = (TextView) view.findViewById(R.id.description_txt);
          this.buybtn = (TextView) view.findViewById(R.id.buybtn);
          this.sharebtn = (TextView) view.findViewById(R.id.sharebtn);
          this.price_curr = (TextView) view.findViewById(R.id.price_curr);
  
      }
  }
  </code></pre>
  
  <p>}</p>