API Demo GestureBuilderActivity分析一
在看API Demo中的GestureBuilderActivity时候遇到了一个比较恶心的问题:

本来想看Add gesture这个Button的点击事件是如何写的,但是根据他的id没有能找到
但是根据代码中函数的名字和断点调试发现走的就是下面的函数:
仔细一看原来定义这个Button的时候有一个属性android:onClick="addGesture"
However, instead of applying anOnClickListenerto the button in your activity, you can assign a method to your button in the XML layout, using theandroid:onClickattribute. For example:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
Now, when a user clicks the button, the Android system calls the activity'sselfDestruct(View)method. In order for this to work, the method must be public and accept aViewas its only parameter. For example:
public void selfDestruct(View view) {
// Kabloey
}
TheViewpassed into the method is a reference to the widget that was clicked.