API Demo GestureBuilderActivity分析一

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


本来想看Add gesture这个Button的点击事件是如何写的,但是根据他的id没有能找到

<Button android:id="@+id/addButton" android:onClick="addGesture" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false" android:text="@string/button_add" />但是根据代码中函数的名字和断点调试发现走的就是下面的函数:

@SuppressWarnings({"UnusedDeclaration"}) public void addGesture(View v) { Intent intent = new Intent(this, CreateGestureActivity.class); startActivityForResult(intent, REQUEST_NEW_GESTURE); }仔细一看原来定义这个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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值