Andriod 对话框
在Activity中可以调用showDialog()来显示一个对话框,覆盖Activity的onCreateDialog方法,在这个方法中创建对话框,返回一个Dialog对象。
1.最简单的对话框
[java]
AlertDialog.Builder b=new AlertDialog.Builder(this);
b.setTitle("简单的");
b.setMessage("this is a 易做图 dialog");
b.setPositiveButton("是", new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
}
});
b.setNegativeButton("否", new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
}
});
return b.create();
AlertDialog.Builder b=new AlertDialog.Builder(this);
b.setTitle("简单的");
b.setMessage("this is a 易做图 dialog");
b.setPositiveButton("是", new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
}
});
b.setNegativeButton("否", new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
}
});
return b.create();
效果如下
2.列表对话框
[java]
b.setTitle("列表");
//b.setMessage("message");这行代码不要有
b.setItems(items, new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();
}
});
return b.create();
b.setTitle("列表");
//b.setMessage("message");这行代码不要有
b.setItems(items, new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();
}
});
return b.create();items是一个String数组
效果图
3.单选对话框
[java]
b.setTitle("请选择颜色");
b.setSingleChoiceItems(items, -1, new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();
}
});
b.setPositiveButton("是", new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
补充:移动开发 , Android ,