2016-05-27 7 views
0

アンドロイドスタジオにアラートボックスを作成しようとしています。ボタンをクリックするともう1つのレイアウトを表示する2つのxmlと1つのアクティビティクラスがあります。 私はエラーを取得しています、ここMainActivity私はアンドロイドスタジオにアラートボックスを作成しています

このラインで
cancelBookingButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      LayoutInflater inflater = getLayoutInflater(); 
      View alertLayout = inflater.inflate(R.layout.alert_cancel_confirm, null); 
      final TextView disAgree = (TextView) alertLayout.findViewById(R.id.TextDisagree); 
      final TextView Agree = (TextView) alertLayout.findViewById(R.id.TextAgree); 


      AlertDialog.Builder alert = new AlertDialog.Builder(this); 
      alert.setTitle("Current Booking"); 
      // This will set the view from XML inside ALertDialog 
      alert.setView(alertLayout); 
      // disabling cancel of AlertDialog on click of back button and outside touch 

      alert.setCancelable(false); 

      AlertDialog dialog = alert.create(); 
      dialog.show(); 
     } 
    }); 

の私のコードは、私がエラーBuilderで

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

を適用することはできません 私はこれを取得していますなぜすべてのアイデアを取得しています。

+0

'新しいAlertDialog.Builder(MainActivity.this)を試してみてください;' 'どこMainActivity'は、このコードがである、アクティビティのクラス名です – Titus

+0

あなたもカスタムダイアログでこれを達成することができます@Firdoeshkhan。 。 – Dhiraj

答えて

0
AlertDialog.Builder alert = new AlertDialog.Builder(YourActivity.this); 
      alert.setTitle("Current Booking"); 
      // This will set the view from XML inside ALertDialog 
      alert.setView(alertLayout); 
      // disabling cancel of AlertDialog on click of back button and outside touch 

      alert.setCancelable(false); 

      AlertDialog dialog = alert.create(); 
      dialog.show(); 
関連する問題