开发者

Overriding trackpad click

I have a ListActivity; and for each item in the ListView there is a checkbox.

When you touch a list item, another Activity launches.

When you use the trackpad/trackball to highlight (read: select) an item and click the tra开发者_StackOverflow社区ckpad, it essentially simulates touching the item. This causes my other Activity to launch.

I would like clicking the trackpad to check the checkbox of the highlighted item. Is there a handler I can override to do this?


You need to override the onTrackballEvent(MotionEvent) method and catch ACTION_DOWN. Here is an example of how to do this:

@Override
    public boolean onTrackballEvent(MotionEvent event) {

        switch(event.getAction()){
        case MotionEvent.ACTION_DOWN:
            //Do your work here
            return true;
        }

        return super.onTrackballEvent(event);
    }

Hope this works for you!


Not sure on a definite answer to this, but one thing worth researching is android:focusable.

I think your best bet is to make the List Items themselves not focusable, but the checkboxes focusable. This way when the user scrolls with the trackball/pad it will switch focus between the checkboxes instead of the list items, and behave in the way you want. This won't affect touch events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜