Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onkeydown what's the diference between return false and return super.onkeydown()?

Tags:

android

I put a list view inside a linearlayout,and I want to override onkeydown() method in ListView ,and I don't control the focus, just change some variables in onkeydown(),I want system do as if I haven't override the onkeydown method.what should I do?return false? or return super.onkeyDown()?.It will be very nice for any help. thank you in advance.

enter image description here

there are three listviews,and a b c are three item of listviews. when c is focused, when I press left arrow on keybord, then a get focus by default. And I want the first item in listview2 get focus how can I do?

like image 837
zyunchen Avatar asked Sep 14 '11 03:09

zyunchen


2 Answers

ntc is not exactly correct. OS does not use reflection to get your base class' handler.

If you return false, you explicitly tell OS that you do not want to handle this event; OS calls the View's parent handler then (as your test shows); this happens until event got handled or top View is reached.

If you call super.OnKeyDown() you allow your base class to process event. Note that it's a base class' handler serving same view, not parent view; don't confuse here.

So, using one or the other depends on your view's behavior desired.

I supose in your case you need return super.onKeyDown();

like image 154
port443 Avatar answered Nov 09 '22 21:11

port443


super.onkeyDown()- this puts the burden on super class to handle the onKeyDown event by your own wish (You explicitly say to handle it). when you return false, android assumes that you have not handled the onKeyDown event and super.onKeyDown() gets called by default (without you calling it).

like image 1
ngesh Avatar answered Nov 09 '22 21:11

ngesh