- 论坛徽章:
- 0
|
和c#,vc中点击一个按键,随后进行的处理很类似。
功通过 Button button = (Button)findViewById(R.id.corky); 这个操作,采用的是钩子函数从屏幕上
获取某个对象的句柄。 button就是这个按键的句柄,下面的操作就可以拿这个句柄说事了。
button.setOnClickListener(mCorkyListener); 这句就是设置按键的点击监听函数。
下面就是点击的具体处理函数。
public class SendResult extends Activity
{
/**
* Initialization of the Screen after it is first created. Must at least
* call setContentView() to
* describe what is to be displayed in the screen.
*/
protected void onCreate(Bundle savedValues)
{
...
// Listen for button clicks.
Button button = (Button)findViewById(R.id.corky);
button.setOnClickListener(mCorkyListener);
}
// Create an anonymous class to act as a button click listener.
private OnClickListener mCorkyListener = new OnClickListener()
{
public void onClick(View v)
{
// To send a result, simply call setResult() before your
// activity is finished.
setResult(RESULT_OK, "Corky!");
finish();
}
};
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/80919/showart_1969079.html |
|