首页 > 解决方案 > 如何创建一个根据时间隐藏其选择项的警报对话框

问题描述

我正在 android 中实现一个 singleChoiceItems 警报对话框,但我想检查一下,以便数组中的某些项目不会根据时间显示。

这是可能的还是有什么方法可以代替警报对话框?

标签: javaandroidandroid-alertdialog

解决方案


这是一个简单的示例,如何检查时间并在“true”时更改项目。对话框是一个对象,你可以在不同的位置调用biulder.*来调用它的属性。

String[] colurs ={"Red","Blue","Green"};

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("Pick Colour")
        .setItems(colurs, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // The 'which' argument contains the index position
                // of the selected item
            }
        });
if(currentThreadTimeMillis()>1000){
    colurs[0]="New1";
    colurs[1]="New2";

    builder.setTitle("Pick Colour").setItems(colurs, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // The 'which' argument contains the index position
            // of the selected item
        }
    });
}
builder.create();
builder.show();

推荐阅读