Question

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?

Was it helpful?

Solution

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!

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top