English 中文(简体)
多渠道帮助
原标题:Android multi-touch help

So, I m developing an app and need to have two buttons pressed at the same time. I need the events for the buttons to be triggered when pressed(which is at the same time, too).

一辆汽车——我已经离开、右边、前面和背。 我需要向前推进,并合力争取正确转变。

这里是我的手法,但出于某种原因,当我向各州发出新闻时,只触发了首先报警的县。 任何想法?

    // Handle touches of the navigation arrows
    public boolean onTouch(View v, MotionEvent theMotion) {
        switch (theMotion.getAction()) {
        // A button was PRESSED
        case MotionEvent.ACTION_DOWN:
            switch (v.getId()) { // Which button?
            case R.id.freestyle_upArrow: // The upArrow
                bt.sendNXTcommand(MOTOR_B_FORWARD, 720);
                break;
            case R.id.freestyle_downArrow: // The downArrow
                bt.sendNXTcommand(MOTOR_B_BACKWARD, 720);
                break;
            case R.id.freestyle_leftArrow: // The leftArrow
                bt.sendNXTcommand(MOTOR_A_LEFT, 720);
                break;
            case R.id.freestyle_rightArrow: // The rightArrow
                bt.sendNXTcommand(MOTOR_A_RIGHT, 720);
                break;
            }
            break;
        // A button was RELEASED
        case MotionEvent.ACTION_UP:
            switch (v.getId()) { // Which button?
            case R.id.freestyle_upArrow: // The upArrow
                bt.sendNXTcommand(MOTOR_B_STOP, 0);
                break;
            case R.id.freestyle_downArrow: // The downArrow
                bt.sendNXTcommand(MOTOR_B_STOP, 0);
                break;
            case R.id.freestyle_leftArrow: // The leftArrow
                break;
            case R.id.freestyle_rightArrow: // The rightArrow
                break;
            }
            break;
        }
        return true;
    }

因此,是否有任何想法? 这是否与我的屏幕上允许的点数有关?

PHONE SPECS:Samsunglaxy Ace entre Anders on firmware 2.2.1

Regards,

里。

最佳回答

Using

switch (event.getAction() & MotionEvent.ACTION_MASK)

You want to look for

MotionEvent.ACTION_POINTER_UP
MotionEvent.ACTION_POINTER_DOWN

For the second finger. Keep in mind you will get a ACTION_POINTER_UP no matter which finger is lifted first

问题回答

for that you have check whether ACTION_DOWN(single touch) and ACTION_POINTER_DOWN(Multi touch) based on that create your logic. note: ACTION_POINTER means multitouch itself





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签