安卓自定义函数中:button按钮添加时间setOnClickListener后运行出错
privatevoidsetInterface(finalDialogdialog){//TODOAuto-generatedmethodstubButtonb=(But...
private void setInterface(final Dialog dialog) {
// TODO Auto-generated method stub
Button b=(Button)findViewById(R.id.submit);
OnClickListener l=new Button.OnClickListener(){
// @Override
public void onClick(View v) {
// // TODO Auto-generated method stub
Context context=getApplicationContext();
TextView tv=(TextView)findViewById(R.id.username);
TextView username=(TextView)findViewById(R.id.username_edit);
tv.setText(username.getText());
dialog.dismiss();
}
};
b.setOnClickListener(l);
////
//add to canall
Button b1=(Button)findViewById(R.id.cancel);
OnClickListener l2=new Button.OnClickListener(){
// @Override
public void onClick(View v) {
// // TODO Auto-generated method stub
dialog.dismiss();
}
};
b1.setOnClickListener(l2);
}
运行到
b1.setOnClickListener(l2);与 b.setOnClickListener(l);处就报错,提示如下(Android 4.0) 展开
// TODO Auto-generated method stub
Button b=(Button)findViewById(R.id.submit);
OnClickListener l=new Button.OnClickListener(){
// @Override
public void onClick(View v) {
// // TODO Auto-generated method stub
Context context=getApplicationContext();
TextView tv=(TextView)findViewById(R.id.username);
TextView username=(TextView)findViewById(R.id.username_edit);
tv.setText(username.getText());
dialog.dismiss();
}
};
b.setOnClickListener(l);
////
//add to canall
Button b1=(Button)findViewById(R.id.cancel);
OnClickListener l2=new Button.OnClickListener(){
// @Override
public void onClick(View v) {
// // TODO Auto-generated method stub
dialog.dismiss();
}
};
b1.setOnClickListener(l2);
}
运行到
b1.setOnClickListener(l2);与 b.setOnClickListener(l);处就报错,提示如下(Android 4.0) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询