Button设定点击事件
Button设定点击事件
先定义一个Button
变量,然后在OnCreate
中找到它,即add_new_order =findViewById(R.id.add_new)
,然后设定点击事件即可。
public class MainActivity extends AppCompatActivity {
private String TAG="CADCAD";
private Button setting,add_new_order,search_order;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG,"-----------------new------------------");
setting =findViewById(R.id.setting);
add_new_order =findViewById(R.id.add_new);
setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
});
add_new_order.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add_new_order();
}
});
}
}
CAD加油!欢迎跟我一起讨论学习算法,QQ:1401650042