title: How to select one particular view from group of view's?
body: <p>For an app I need to develop, I need to be able to <code>select one view</code> from <code>ViewGroup</code> when user <code>long press</code> on the <code>view</code> have to popup an alert dialog, from that i will select options depending on the requirement, those are delete view and change background color for that particular view. I am creating different custom view's ( Custom view extends from View) and It has Touchlistener's. Dynamically attaching those view's to layout (RelativeLayout). Let us assume my layout having 3 views.</p>
  
  <p><strong>My questions:</strong></p>
  
  <ul>
  <li>I want to select one view from the list of available view's on the layout. </li>
  <li>How to restrict the Custom view size instead of occupying full parent view.</li>
  </ul>
  
  <p><strong>I am facing Problem's like this:</strong> Look at this image if i set background color for custom view it look like this, Actually i was set for layout background color White here custom view occupies full screen. so, unable to see parent background color. Here problem with customview size, unable to restrict the customview size rather than occupying full parent view. even if i touch outside of my custom view, the touch listeners of custom view was triggering. i want to restrict those touch listeners upto my customview only..</p>
  
  <p><img src="https://i.stack.imgur.com/PtUPj.png" alt="enter image description here">. </p>
  
  <p><strong>Main Requirement:</strong>
  Finally i want to be achieve like this below image, Now i am able to add more custom view's to layout,but unable to delete selected one. When i long press on any one of the view from the layout, it should popup one alert dialog with two buttons, if i select one selected view should be delete for another selection background color change.</p>
  
  <p><img src="https://i.stack.imgur.com/XDzRo.png" alt="enter image description here"></p>
  
  <p><strong>RelaventCode:</strong> i am adding view to layout like this.</p>
  
  <pre><code>findViewById(R.id.line).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
          CustomView drawView = new CustomView(context);
          frame.addView(drawView);
     }
  });
  </code></pre>
  
  <p>and this is the customview :</p>
  
  <pre><code>public class CustomView extends View {
  
  public CustomView (Context context) {
      super(context);
      init();
  }
  private void init() {
  
      Paint paint = new Paint();
      Paint pai = new Paint();         
      Path path = new Path();
      paint.setColor(Color.RED);
      paint.setStyle(Paint.Style.STROKE);
      paint.setStrokeWidth(5);
      path.lineTo(50, 100);       
  }
  
  @Override
  public void onDraw(Canvas canvas) {
      path.setFillType(Path.FillType.EVEN_ODD);
      path.moveTo(Top_Point.x, Top_Point.y);
      path.lineTo(Right_Point.x, Right_Point.y);
      path.lineTo(Left_Point.x, Left_Point.y);
      path.lineTo(Top_Point.x, Top_Point.y);
      path.close();
      canvas.drawPath(path, Inner_Paint);
      canvas.drawLine(Top_Point.x, Top_Point.y, Right_Point.x, Right_Point.y,
              Lines_Paint);
      canvas.drawLine(Right_Point.x, Right_Point.y, Left_Point.x,
              Left_Point.y, Lines_Paint);
      canvas.drawLine(Left_Point.x, Left_Point.y, Top_Point.x, Top_Point.y,
              Lines_Paint);
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {     
      switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
          PointF NewP = new PointF(0, 0);
          NewP.x = event.getX();
          NewP.y = event.getY();
          if (TopTouchArea.contains(event.getX(), event.getY())) {
              currentTouch = TOUCH_TOP;
          } else if (RightTouchArea.contains(event.getX(), event.getY())) {
              currentTouch = TOUCH_RIGHT;
          } else if (LeftTouchArea.contains(event.getX(), event.getY())) {
              currentTouch = TOUCH_LEFT;
          } else if (a) {
              Translate_Point.x = event.getX();
              Translate_Point.y = event.getY();
              currentTouch = Inner_Touch;
              return true; // Return false if user touches none of the
                              // corners
          } else {
              return false;
          }
  
          return true; 
      case MotionEvent.ACTION_MOVE:
          switch (currentTouch) {
          case TOUCH_TOP:
                 /*  ------ */
          case TOUCH_RIGHT:
                 /*   ----- */
              invalidate();
              return true;
          case TOUCH_LEFT:
           /* ------ */
              invalidate();
              return true;
          case Inner_Touch:
              /* ------ */
              invalidate();
              return true;
          }           
          return false; 
      case MotionEvent.ACTION_UP:         
          switch (currentTouch) {
          case TOUCH_TOP:
              /* ----- */
              return true;
          case TOUCH_RIGHT:
              /* ----- */
              return true;
          case TOUCH_LEFT:
              /* ----- */
              return true;
          case Inner_Touch:
              /* ----- */
              invalidate();  
          return true;
          }           
          return false;
      }
      return super.onTouchEvent(event);
  }
  </code></pre>