1

我有一个对话框窗口,它必须包含容器和两个单击侦听器才能关闭对话框,我希望我只显示一次,我使用此代码,但它根本不显示!

有什么帮助吗?

    SharedPreferences setting = getSharedPreferences("dialogprefs", 0);
    final SharedPreferences.Editor editor = setting.edit(); 
    {
           final Dialog dialog = new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.setContentView(R.layout.hint1);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setTitle("Hint");
            View masterView = dialog.findViewById(R.id.LinearLayout1);
            masterView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    editor.putString("dialogshow", "0".toString());
                    editor.commit();
                }
            });
                View masterView1 = dialog.findViewById(R.id.imageView1);
                masterView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                        editor.putString("dialogshow", "0".toString());
                        editor.commit();
                    }
            });
            if (setting.getString("dialogshow" , "0").equals("0")) {
                dialog.dismiss();
            }
            else {
            dialog.show();  
            }
    }
4

1 回答 1

0

假设这setting.getString("dialogShow", "0")意味着类似的事情,getString(name, defaultValue)那么默认值是"0"如果尚未设置首选项,这意味着对话框将永远不会显示一次。也许你的意思是setting.getString("dialogShow", "1")

于 2013-09-24T18:05:21.463 回答