android开发,两个按钮跳转到不同的页面,该注意什么?我的第一个可以挑,第二个就崩了,求指教,谢谢!
privateButtonmainbtn=null;privateButtonmainbtn2=null;@OverrideprotectedvoidonCreate(B...
private Button mainbtn = null;
private Button mainbtn2 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainbtn = (Button)findViewById(R.id.datepicker_button);
mainbtn.setOnClickListener(xx);
mainbtn2 = (Button)findViewById(R.id.timepicker_button);
mainbtn2.setOnClickListener(xx2);
}
private OnClickListener xx = new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(MainActivity.this, DatePickerActivity.class);
startActivity(intent);
}
};
private OnClickListener xx2 = new OnClickListener()
{
public void onClick(View v2)
{
Intent intent2 = new Intent();
intent2.setClass(MainActivity.this, TimePickerActivity.class);
startActivity(intent2);
}
}; 展开
private Button mainbtn2 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainbtn = (Button)findViewById(R.id.datepicker_button);
mainbtn.setOnClickListener(xx);
mainbtn2 = (Button)findViewById(R.id.timepicker_button);
mainbtn2.setOnClickListener(xx2);
}
private OnClickListener xx = new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(MainActivity.this, DatePickerActivity.class);
startActivity(intent);
}
};
private OnClickListener xx2 = new OnClickListener()
{
public void onClick(View v2)
{
Intent intent2 = new Intent();
intent2.setClass(MainActivity.this, TimePickerActivity.class);
startActivity(intent2);
}
}; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询