标签:onclick roi import lis com ide you find and
如下代码是关于Android为按钮添加相应事件的代码。Button button =(Button) this.findViewById(R.id.button);
2、编写按钮监听器
private class ButtonClickListener implements View.OnClickListener{
public void onClick(View v) {
findViewById(R.id.filename);
}
}
此监听器实现View.OnClickListener接口,实现onClick方法。3、为按钮添加此监听器
button.setOnClickListener(new ButtonClickListener());
代码:
package com.feng.files;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button =(Button) this.findViewById(R.id.button);
button.setOnClickListener(new ButtonClickListener());
}
private class ButtonClickListener implements View.OnClickListener{
public void onClick(View v) {
findViewById(R.id.filename);
}
}
}
标签:onclick roi import lis com ide you find and
原文地址:https://blog.51cto.com/14122754/2501167