看看,怎么给里面的四个按钮带代码哪儿添加监听器,谢谢
public class Alert01 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutInflater factory = LayoutInflater.from(Alert01.this);
//得到自定义对话框
final View DialogView = factory.inflate(R.layout.dialog01, null);
AlertDialog dialog = new AlertDialog.Builder(Alert01.this)
.setTitle("请选择操作")
.setView(DialogView)
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
;
}
}).setNeutralButton("退出", null).create();
dialog.show();
}
}
public class Alert01 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutInflater factory = LayoutInflater.from(Alert01.this);
//得到自定义对话框
final View DialogView = factory.inflate(R.layout.dialog01, null);
AlertDialog dialog = new AlertDialog.Builder(Alert01.this)
.setTitle("请选择操作")
.setView(DialogView)
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
;
}
}).setNeutralButton("退出", null).create();
dialog.show();
}
}
public void onClick(DialogInterface dialog, int which) {
;
}
不是已经添加了吗?
我说的是.setView(DialogView)这个DialogView里面的按钮。。谢谢
Button button = (Button)DialogView.findViewById("R.id.button");
button.setOnclickListener(this);写在你声明了DialogView之后就可以了
Button button = (Button)DialogView.findViewById(R.id.button);
button.setOnclickListener(this);刚打多两个引号了,呵呵
为什么不行啊。 你要写在final View DialogView = factory.inflate(R.layout.dialog01, null);
之后