title: Touch listener and changing parent
body: <p>I apologize for my English. I have a problem.
  I use a listeners LongClick and TouchListener.</p>
  
  <p>In the long click - the view is removed and the parent view is inserted into the other parent.
  Touch stops working, because there was a change parent.</p>
  
  <p>How do I keep TouchListener to View?</p>
  
  <pre><code>static boolean drag = false;
  static View parent;
  static OnLongClickListener olcl = new OnLongClickListener() {
      @Override
      public boolean onLongClick(View v) {
  
          if(!drag) {
              parent = (View) v.getParent();
              int[] loc = {0, 0};
              v.getLocationOnScreen(loc);
              ((ViewGroup) parent).removeView(v);
              Main.mainRelative.addView(v);
  
              RelativeLayout.LayoutParams par = (LayoutParams) v.getLayoutParams();
              par.leftMargin = loc[0];
              par.topMargin = loc[1];
              v.setLayoutParams(par);
  
              drag = true;
              return true;
          }
          return false;
      }
  };
  
  static OnTouchListener otl = new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
  
          if(v.getParent() != null &amp;&amp; v.getParent() == Main.mainRelative) {
              //!!!!!!!!!!!!!
              RelativeLayout.LayoutParams par = (LayoutParams) v.getLayoutParams();
              par.leftMargin = (int) (event.getRawX() - v.getWidth()/2);
              par.topMargin = (int) (event.getRawY() - v.getHeight()/1.2);
              v.setLayoutParams(par);
  
              for(int y = 0; y &lt; Main.radioGroupLeftMain.getChildCount(); y++) {
                  RadioButton rb = (RadioButton) ((ViewGroup) Main.radioGroupLeftMain.getChildAt(y)).getChildAt(0);
                  if(checkHit((int)event.getRawX(), (int)event.getRawY(), rb)) {
                      rb.setChecked(true);
                  } else {
                      rb.setChecked(false);
                  }
  
                  if(event.getAction() == MotionEvent.ACTION_UP) {
  
  
                      try { ((ViewGroup) v.getParent()).removeView(v); } catch(Exception e) {};
                      if(v.getVisibility() == View.VISIBLE) {
                          ((ViewGroup) parent).addView(v);
                      }
                      drag = false;
                  }
              }   
          }
  
  
  
          return false;
      }
  };
  
  public static boolean checkHit(int x, int y, View v) {
      int[] loc = {0, 0};
      v.getLocationOnScreen(loc);
      Rect rv = new Rect(loc[0], loc[1], loc[0]+v.getWidth(), loc[1]+v.getHeight());
  
  
      return rv.contains(x, y);
  }
  </code></pre>