自定义对话框中的按钮响应跳转
用xml写的一个对话框中的按钮,如何在dialog.java中给它设置监听?
用xml写的一个对话框中的按钮,如何在dialog.java中给它设置监听?
2018-11-14
public class DialogActivity extends Activity implements View.OnClickListener{
...
public void showCustomDialog(){
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.layout_dialog,null);
Button btn_customdialog = (Button) view.findViewById(R.id.btncustomdialog);
//为自定义按钮注册监听
btn_customdialog.setOnClickListener(this);
...
}@Override
public void onClick(View v) {
switch (v.getId()) {
...
case R.id.btncustomdialog:
//自定义对话框内部按钮点击事件响应逻辑
customDialog.dismiss();
break;
}
}
...
}
举报