2

私がやろうとしているのは、マルチタッチ ボタンを処理することです。6 つのボタンがあり、ユーザーは 1 つから 6 つのボタンをタッチできます。問題は、MotionEvent最大 3 つのポインターを処理できることですが、必要なのは最大 6 つのポインターです。何か助けてください。

これはコードです:

public class MultitouchtestActivity extends Activity {
    private class TouchListener implements OnTouchListener {

        @Override
        public boolean onTouch(final View v, final MotionEvent event) {


            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                switch (v.getId()) {
                case R.id.button1:
                    sqText = "Square 1 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                case R.id.button2:
                    sq1Text = "Square 2 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                case R.id.button3:
                    sq2Text = "Square 3 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                case R.id.button4:
                    sq3Text = "Square 4 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                case R.id.button5:
                    sq4Text = "Square 5 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                case R.id.button6:
                    sq5Text = "Square 6 Pressed::Pointer count = "
                            + String.valueOf(event.getPointerCount());
                    break;
                }

            } else if (event.getAction() == MotionEvent.ACTION_POINTER_1_DOWN) {
                switch (v.getId()) {
                case R.id.button1:
                    sqText = "Square 1 Pointer1Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button2:
                    sq1Text = "Square 2 Pointer1Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button3:
                    sq2Text = "Square 3 Pointer1Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button4:
                    sq3Text = "Square 4 Pointer1Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                }
            } else if (event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
                switch (v.getId()) {
                case R.id.button1:
                    sqText = "Square 1 Pointer2Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button2:
                    sq1Text = "Square 2 Pointer2Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button3:
                    sq2Text = "Square 3 Pointer2Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button4:
                    sq3Text = "Square 4 Pointer2Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                }
            } else if (event.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {
                switch (v.getId()) {
                case R.id.button1:
                    sqText = "Square 1 Pointer3Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button2:
                    sq1Text = "Square 2 Pointer3Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button3:
                    sq2Text = "Square 3 Pointer3Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                case R.id.button4:
                    sq3Text = "Square 4 Pointer3Down::Pointer count = "
                            + String.valueOf(event.getPointerCount()) + "\n";
                    break;
                }




            }

            // TODO Auto-generated method stub
            return true;
        }
    }

    protected Button sq1;
    protected Button sq2;
    protected Button sq3;
    protected Button sq4;
    protected Button sq5;
    protected Button sq6;

    protected String sqText = new String();
    protected String sq1Text = new String();
    protected String sq2Text = new String();
    protected String sq3Text = new String();
    protected String sq4Text = new String();
    protected String sq5Text = new String();


    private final Handler handler = new Handler();

    private final Runnable mUpdateUITimerTask = new Runnable() {
        @Override
        public void run() {
            // do whatever you want to change here, like:
            updateTextField();
        }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setViews();
        handler.postDelayed(mUpdateUITimerTask, 5000);
    }

    private void setViews() {
        sq1 = (Button) findViewById(R.id.button1);
        sq2 = (Button) findViewById(R.id.button2);
        sq3 = (Button) findViewById(R.id.button3);
        sq4 = (Button) findViewById(R.id.button4);
        sq5 = (Button) findViewById(R.id.button5);
        sq6 = (Button) findViewById(R.id.button6);

        sq1.setOnTouchListener(new TouchListener());
        sq2.setOnTouchListener(new TouchListener());
        sq3.setOnTouchListener(new TouchListener());
        sq4.setOnTouchListener(new TouchListener());
        sq5.setOnTouchListener(new TouchListener());
        sq6.setOnTouchListener(new TouchListener());
    }

    private void updateTextField() {
        final TextView view1 = (TextView) findViewById(R.id.logView);
        final TextView view2 = (TextView) findViewById(R.id.logView1);
        final TextView view3 = (TextView) findViewById(R.id.logView2);
        final TextView view4 = (TextView) findViewById(R.id.logView3);
        final TextView view5 = (TextView) findViewById(R.id.logView4);
        final TextView view6 = (TextView) findViewById(R.id.logView5);

        // view1.append(sqText + "\n");
        view1.setText(sqText);
        view2.setText(sq1Text);
        view3.setText(sq2Text);
        view4.setText(sq3Text);
        view5.setText(sq4Text);
        view6.setText(sq5Text);

        handler.post(mUpdateUITimerTask);
    }
}
4

1 に答える 1

0

Androidで検出できるポインターの数は、デバイスによって異なります。古いものの中には1つしか検出できないものもありますが、最近のものはもっと検出できる場合があります。

市場に公開する場合は、ポインターの少ないデバイスでもアプリが機能することを確認してください。

于 2012-10-27T22:51:19.143 に答える