setOnClickListener 事件记录

android中click事件触发机制

1、在XML直接指定click事件名称

    
Activity中定义方法
    public void btnOnClick(View view){  
        Intent intent = new Intent(mainActivity.this, fristActivity.class);  
        intent.putExtra("data", "mainActivity");  
        startActivity(intent);  
    }

2、Activity中定义OnClickListener接口监听事件

    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        findViewById(R.id.bt_Click).setOnClickListener(onclick);  
    }  
    OnClickListener onclick = new OnClickListener(){  
        @Override  
        public void onClick(View v) {  
            Intent intent = new Intent(mainActivity.this, fristActivity.class);  
            intent.putExtra("data", "mainActivity");  
            startActivity(intent);    
        }  
    }; 

3、在Activity为button指定绑定操作

    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        findViewById(R.id.bt_Click).setOnClickListener(new OnClickListener(){  
            @Override  
            public void onClick(View v) {  
                Intent intent = new Intent(mainActivity.this, fristActivity.class);  
                intent.putExtra("data", "mainActivity");  
                startActivity(intent);            
            }         
        });  
    }

你可能感兴趣的:(setOnClickListener 事件记录)