码迷,mamicode.com
首页 > 其他好文 > 详细

一个监听事件监听多个按钮

时间:2015-03-04 18:52:23      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

 

    private Button btnWrite;
    private Button btnRead;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnRead = (Button) findViewById(R.id.btnRead);
        btnWrite = (Button) findViewById(R.id.btnWrite);
        btnRead.setOnClickListener(new ButtonListener());
        btnWrite.setOnClickListener(new ButtonListener());
    }

    private class ButtonListener implements OnClickListener {

        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.btnRead:
                Toast.makeText(MainActivity.this, "读取", Toast.LENGTH_SHORT)
                        .show();
                break;
            case R.id.btnWrite:
                Toast.makeText(MainActivity.this, "写入", Toast.LENGTH_SHORT)
                        .show();
                break;
            default:
                break;
            }
        }

    }


 

一个监听事件监听多个按钮

标签:

原文地址:http://www.cnblogs.com/yunqingabc/p/4313799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!