2

I want to draw a line and set a click listener on it. When I click the line, a dialog will display. I know how to draw a line on the view, but I want to create something like "a line object", so that I can control and set listener on it.

If anyone knows that, please help me. Thank you :)

Wawa Chen
  • 21
  • 1
  • 3
    Subclass View and call it Line. – Blackbelt Sep 26 '12 at 14:44
  • I did this with an xml object as a rectangle and made it very thin. – O'Mutt Sep 26 '12 at 14:46
  • 1
    I have done something similar where I create a `View` with a small height and background color then add the `setOnClickListener()`. – jnthnjns Sep 26 '12 at 14:47
  • 2
    Keep in mind that if you set your line's height to even 2 or 3 pixels, it will still be very hard for the user to "click" it. There will be a lot of frustration on the user's part. I would recommend using a larger view with a line drawn on it. – Aleks G Sep 26 '12 at 16:07
  • Or, capture the touch in the parent view then ask the Line if its been touched. Then, the Line can use touch slop, either the View default or some calculated value which makes the app respond as desired. I do this with a class of draggable cross hairs on a graph. In parentView.onTouch(), for (Line line:lines){if (line.isTouched(x,y)){} – Simon Sep 26 '12 at 16:39

0 Answers0