Android:AlertDialog显示在模拟器上的按钮单击上,但不在我的手机上

时间:2018-07-26 21:48:59

标签: android alertdialog

我有一个问题,当我在设备上运行apk时,不显示alerdialog,但在模拟器上却显示。这是 onCreate 方法的代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    // Get Location Manager and check for GPS & Network location services
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

        // Build the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        View mView = getLayoutInflater().inflate(R.layout.activity_gps_alert_dialog, null);
        Button positiveBtn = (Button) mView.findViewById(R.id.positiveBtn);
        Button negativeBtn = (Button) mView.findViewById(R.id.negativeBtn);
        positiveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Show location settings when the user acknowledges the alert dialog
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });

        negativeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                System.exit(0);
            }
        });


        builder.setView(mView);
        AlertDialog dialog = builder.create();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();










 goBelNuBtn = (Button) findViewById(R.id.belnuBtn);

        goBelNuBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Build the alert dialog
                final AlertDialog.Builder build = new AlertDialog.Builder(MapsActivity.this);
                final View popupView = getLayoutInflater().inflate(R.layout.belnupopupdialog, null);
                Button callBtn = (Button) popupView.findViewById(R.id.callBtn);
                Button cancelBtn = (Button) popupView.findViewById(R.id.popupAnulerenBtn);
                build.setView(popupView);
                final AlertDialog dialg= build.create();


                callBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(Intent.ACTION_DIAL);
                        String p = "tel:" + getString(R.string.PhoneNumber);
                        i.setData(Uri.parse(p));
                        startActivity(i);
                    }
                });

                cancelBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialg.cancel();
                    }
                });

                dialg.setCancelable(false);
                dialg.setCanceledOnTouchOutside(false);
                dialg.show();
            }

        });

    }

名为Dialg的AlertDialog是一个有问题的人。我尝试了很多设备,不仅是我的,而且什么也没有发生...我还从 final View popupView = getLayoutInflater()。inflate( R.layout.belnupopupdialog,为null); 并不是问题

我注意到当我按下按钮时,上面的照片消失并立即返回。我希望这可以帮助您理解问题。

Button with image Button with no image

0 个答案:

没有答案