覆盖触控板点击

发布于 2024-09-28 15:59:50 字数 187 浏览 2 评论 0原文

我有一个列表活动; ListView 中的每个项目都有一个复选框。

当您触摸列表项时,会启动另一个活动。

当您使用触控板/轨迹球突出显示(读取:选择)某个项目并单击触控板时,它实际上模拟了触摸该项目。这会导致我的其他活动启动。

我想单击触控板来选中突出显示的项目的复选框。是否有一个处理程序可以覆盖来执行此操作?

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 trackpad, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十年九夏 2024-10-05 15:59:50

您需要重写 onTrackballEvent(MotionEvent) 方法并捕获 ACTION_DOWN。以下是如何执行此操作的示例:

@Override
    public boolean onTrackballEvent(MotionEvent event) {

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

        return super.onTrackballEvent(event);
    }

希望这对您有用!

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!

染火枫林 2024-10-05 15:59:50

不确定对此的明确答案,但值得研究的一件事是 android:focusable

我认为最好的选择是使列表项本身不可聚焦,但使复选框可聚焦。这样,当用户使用轨迹球/键盘滚动时,它将在复选框而不是列表项之间切换焦点,并按照您想要的方式运行。这不会影响触摸事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文