0

i would like to know if there is a corresponding class or method in android of become first responder a view like ios. My problem is that i have a scrollable Relative Layout (f1) that belongs at a scroll view (f2). When i try to scroll down the f1 , scrolls the f2. Any ideas? Thank you

karvoynistas
  • 1,257
  • 1
  • 12
  • 29
  • 2
    You may wish to explain what "become first responder a view like ios" means. – CommonsWare Aug 29 '13 at 12:18
  • In general, don't put scrollable views inside other scrollable views. – Simon Aug 29 '13 at 12:22
  • I mean if there is a method like this : https://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/becomeFirstResponder in android – karvoynistas Aug 29 '13 at 12:30
  • Would you mind to explain what a `first responder` actually is? Possibly we know it, but associate a different name with it... – tilpner Aug 29 '13 at 13:01

2 Answers2

1

I presume you want a child view to receive touch events rather than a parent view. You can easily delegate touch events to child views by overriding a view's onTouchEvent() method.

In Android, when a view returns false from it's onTouchEvent() method, the event is propagated down to it's child views. If this is the behavior you need, then override the onTouchEvent() method of the parent view and make it return false on whatever condition you desire.

Anup Cowkur
  • 19,813
  • 6
  • 48
  • 82
  • This solution is very good and could work for me if I hadn't scroll views. The scroll up and scroll down listeners are implemented by the system and i cannot handle them by my self. Thank you anyway! – karvoynistas Aug 29 '13 at 13:17
  • you can extend a scrollview and make your own scrollview where you can override the onScrollChanged() method. See: http://stackoverflow.com/a/10334353/1369222 – Anup Cowkur Aug 29 '13 at 13:25
0

you should use onTouchEvent() and onInterceptTouchEvent():

http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent)

Avadhani Y
  • 7,276
  • 18
  • 55
  • 90
roiberg
  • 12,799
  • 11
  • 54
  • 87