button监听事件

在组件文件main.xml中,对Button加入:
android:onClick="onClick_Event"

在activity中加入以下代码:
public void onClick_Event(View view) {
TextView textview = (TextView)findViewById(R.id.textView1);
textview.setText("你点击了Button");
}

在这个方式中,我们只需要在TestOnClickActivity 中增加一个成员函数onClick_Event(),并在组件文件中加入对其的使用描述即可。
代码结构简单,清晰,代码量也大大减少,并且通过xml文件的可配置性,增长了工程的可维护性,模块化进一步增强!

posted @ 2016-10-18 19:13  EdwardRu  阅读(204)  评论(0编辑  收藏  举报