还剩1页未读,继续阅读
文本内容:
androidButton监听的几种方式http://blog.csdn.net/fangzhengshu/article/details/8102969androidbutton控件目前主要有如下几种监听方式:
1.一个button控件对应一个监听:[j__a] viewplainhttp://blog.csdn.net/fangzhengshu/article/details/8102969\oviewplaincopyhttp://blog.csdn.net/fangzhengshu/article/details/8102969\ocopy
1. Button buttontest;
2. buttontest = Button findViewByIdR.id.button1;
3. buttontest.setOnClickListenernew View.OnClickListener {
4.
5. @Override
6. public void onClickView v {
7. // TODO Auto-generated method stub
8. Log.iTEST button onClick;
9. }
10.};
2.多个button对应一个监听1:[j__a] viewplainhttp://blog.csdn.net/fangzhengshu/article/details/8102969\oviewplaincopyhttp://blog.csdn.net/fangzhengshu/article/details/8102969\ocopy
1.start = Button findViewByIdR.id.button1;
2.stop = Button findViewByIdR.id.button2;
3.start.setOnClickListenermylistener ;
4.stop.setOnClickListenermylistener ;
5.View.OnClickListener mylistener = new View.OnClickListener {
6.
7. @Override
8. public void onClickView v {
9. switch v.getId {
10. case R.id.button1:
11. Log.dTAG Start to recorder video\n;
12. start_recorde;
13. break;
14. case R.id.button2:
15. Log.dTAG Stop to recorder video\n;
16. stop_recorde;
17. break;
18. default:
19. break;
20. }
21. }
22. };
1.多个button对应一个监听2:[j__a] viewplainhttp://blog.csdn.net/fangzhengshu/article/details/8102969\oviewplaincopyhttp://blog.csdn.net/fangzhengshu/article/details/8102969\ocopy
1.public class __inActivity extends Activity implements View.OnClickListener{
2. //界面元素
3. private Button start;
4. private Button stop;
5.
6. @Override
7. public void onCreateBundle s__edInstan__State {
8. super.onCreates__edInstan__State;
9. setContentViewR.layout.activity___in;
10.
11. start = Button findViewByIdR.id.button1;
12. stop = Button findViewByIdR.id.button2;
13. start.setOnClickListenerthis;
14. stop.setOnClickListenerthis;
15. }
16.
17. @Override
18. public boolean onCreateOption__enuMenu menu {
19. getMenuInflater.inflateR.menu.activity___in menu;
20. return true;
21. }
22.
23. @Override
24. public void onClickView v {
25. switch v.getId {
26. case R.id.button1:
27. Log.dTAG Start to recorder video\n;
28. break;
29. case R.id.button2:
30. Log.dTAG Stop to recorder video\n;
31. break;
32. default:
33. break;
34. }
35. }
36.
37.}
1.xml中绑定监听:[html] viewplainhttp://blog.csdn.net/fangzhengshu/article/details/8102969\oviewplaincopyhttp://blog.csdn.net/fangzhengshu/article/details/8102969\ocopy
1.Button
2.android:id=@+id/button1
3.android:layout_height=wrap_content
4.android:layout_width=wrap_content
5.android:onClick=mybuttonlistener
6./Button 对应j__a代码如下:[j__a] viewplainhttp://blog.csdn.net/fangzhengshu/article/details/8102969\oviewplaincopyhttp://blog.csdn.net/fangzhengshu/article/details/8102969\ocopy
7.Button btn = Button findViewByIdR.id.button1;
8.public void mybuttonlistenerView target{
9. //do something5
10.} 从个人角度来讲,不推荐使用第四种实现方式。