好的,所以我想有一个自定义对话框,但我无法弄清楚我的生活如何使它在调用函数时出现。显示自定义对话框
public void addHomework() {
final Dialog alert = new Dialog(this);
alert.setTitle("Add Homework");
alert.setContentView(R.layout.homework_item_entry);
Button add_button = (Button) findViewById(R.id.add_homework_button);
Button cancel_button = (Button) findViewById(R.id.cancel_homework_button);
add_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(ClassHomeworkList.this, "Adding homework", Toast.LENGTH_SHORT).show();
}
});
cancel_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
alert.dismiss();
}
});
alert.show();
}
我该怎么办?
现在会发生什么? – 2010-09-15 20:34:33
一点都没有,没有出现。 – Chiggins 2010-09-15 21:00:18
你应该真的使用onCreateDialog来代替,它有助于处理像旋转屏幕时恢复的事情。只要基本上移动你的构建器代码,然后返回它处理剩下的对话框。 – schwiz 2010-09-15 21:01:51