0

我想要一点帮助。

我正在尝试提取“触摸”信息并发送它。对于调试,我想打印到我提取到日志的信息。我使用了 Log.v,但它不起作用。每次触摸屏幕时,我都会看到新消息,但没有我写的内容。我认为我的视图定义有问题。我想定义所有的屏幕。附件是我的代码和日志消息。

>1. "TouchScreen.java"
    public class TouchScreenActivity extends Activity {
        /** Called when the activity is first created. */
        View mButtonLable;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            mButtonLable = findViewById(R.id.super_view);
            mButtonLable.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
            int i, len, id;
            float x, y, t;

            len = motionEvent.getPointerCount();
            float[][] touch = new float[len][4];
            for (i = 0; i < len - 1; i++) {
                   id = motionEvent.getPointerId(i);
                    x = motionEvent.getX(i);
                    y = motionEvent.getY(i);
                    t = motionEvent.getEventTime();
                    touch[i][0] = x;*
                    touch[i][1] = y;
                    touch[i][2] = id;
                    touch[i][3] = t;
                    Log.v("TouchScreenActity", "x = " + x + ", y = " + y
                    + ", id = " + id + ",t = " + t);
                }

                return false;
            }

        });


    }

    >2."main.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

        <TextView
            android:id="@+id/super_view"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="2"
            android:background="#f00" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />

    </LinearLayout>

my Logcat
>04-18 23:46:52.390: D/HierarchicalStateMachine(301): processMsg: SupplicantStartedState
>04-18 23:46:52.390: D/WifiStateMachine(301): SupplicantStartedState{ what=65574 when=-19ms }
>04-18 23:46:52.390: I/wpa_supplicant(19652): SCAN_RESULTS : [2] 
>04-18 23:46:52.400: D/HierarchicalStateMachine(301): handleMessage: X
>04-18 23:46:52.400: D/HierarchicalStateMachine(301): handleMessage: E msg.what=65575
>04-18 23:46:52.400: D/HierarchicalStateMachine(301): processMsg: DisconnectedState
>04-18 23:46:52.400: D/WifiStateMachine(301): DisconnectedState{ what=65575 when=-17ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@40877448 }
>04-18 23:46:52.400: D/WifiStateMachine(301): setDetailed state, old =SCANNING and new >state=CONNECTING
>04-18 23:46:52.400: D/HierarchicalStateMachine(301): processMsg: ConnectModeState
>04-18 23:46:52.400: D/WifiStateMachine(301): ConnectModeState{ what=65575 when=-18ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@40877448 }
>04-18 23:46:52.400: D/HierarchicalStateMachine(301): handleMessage: X
>04-18 23:46:52.400: D/WpsStateMachine(301): InactiveState{ what=65575 when=-1ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@40877448 }
>04-18 23:46:52.460: I/wpa_supplicant(19652): Wireless event: new AP: 00:21:27:f5:3d:20
>04-18 23:46:52.460: I/wpa_supplicant(19652): CTRL-EVENT-STATE-CHANGE id=4 state=4 >BSSID=00:21:27:f5:3d:20
>04-18 23:46:52.460: V/WifiMonitor(301): Event [CTRL-EVENT-STATE-CHANGE id=4 state=4 >BSSID=00:21:27:f5:3d:20]
>04-18 23:46:52.460: D/HierarchicalStateMachine(301): handleMessage: E msg.what=65575
>04-18 23:46:52.460: D/HierarchicalStateMachine(301): processMsg: DisconnectedState
>04-18 23:46:52.470: I/wpa_supplicant(19652): Current ps mode is 0
>04-18 23:46:52.470: I/wpa_supplicant(19652): Associated with 00:21:27:f5:3d:20
>04-18 23:46:52.470: I/wpa_supplicant(19652): CTRL-EVENT-STATE-CHANGE id=4 state=7 >BSSID=00:00:00:00:00:00
>04-18 23:46:52.470: D/WifiStateMachine(301): DisconnectedState{ what=65575 when=-1ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@413643e0 }
>04-18 23:46:52.470: I/wpa_supplicant(19652): CTRL-EVENT-CONNECTED - Connection to >00:21:27:f5:3d:20 completed (reauth) [id=4 id_str=]
>04-18 23:46:52.470: D/WifiStateMachine(301): setDetailed state, old =CONNECTING and new >state=CONNECTING
>04-18 23:46:52.470: D/HierarchicalStateMachine(301): processMsg: ConnectModeState
>04-18 23:46:52.470: D/WifiStateMachine(301): ConnectModeState{ what=65575 when=-2ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@413643e0 }
>04-18 23:46:52.470: D/HierarchicalStateMachine(301): handleMessage: X
>04-18 23:46:52.470: D/WpsStateMachine(301): InactiveState{ what=65575 when=-1ms >obj=android.net.wifi.WifiStateMachine$StateChangeResult@413643e0 }
4

1 回答 1

0

我认为您的问题出在 for 循环声明中。

 for (i = 0; i < len - 1; i++) 

如果你的 len 为 1,这个循环的主体将永远不会被执行,不是吗?只需将其更改为:

 for (i = 0; i < len; i++)
于 2012-04-22T20:48:40.573 回答