2017-09-07 11 views
-3

私の問題は、私はuがAlertDialogボタンのエラー

 public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, final View convertView, ViewGroup parent) { 

      final ImageView imageView = new ImageView(context); 
      imageView.setImageResource(imgList[groupPosition][childPosition]); 
      imageView.setLayoutParams(new ViewGroup.LayoutParams(350,350)); 
      imageView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        AlertDialog alt = new AlertDialog.Builder(MainActivity.this).create(); 
        alt.setTitle("Esfandune"); 
        alt.setIcon(R.drawable.ic_launcher); 
        alt.setMessage("Esfandune.ir is the best !"); 
        alt.setButton("yes", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface arg0, int arg1) { 
          Toast.makeText(getApplicationContext(), 

// 
            "You clicked on yes", Toast.LENGTH_SHORT).show(); 

} 
        }); 

画像

enter image description here

答えて

1

あなたはとてもコード上記のコードを記述するとあなたはまた、正のボタンを使用することができます

alt.setButton(DialogInterface.BUTTON_POSITIVE, "yes", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface arg0, int arg1) { 
       Toast.makeText(getApplicationContext(),"You clicked on yes", Toast.LENGTH_SHORT).show(); 

      } 
     }); 
0

だけsetButtonに最初の引数を追加した画像で私のエラーを見ることができますExpandableListViewでalertDialog、 でボタンを設定しカントでありますこのような。

AlertDialog alt = new AlertDialog.Builder(MainActivity.this).create(); 
        alt.setTitle("Esfandune"); 
        alt.setIcon(R.drawable.ic_launcher); 
        alt.setMessage("Esfandune.ir is the best !"); 
        alt.setButton(DialogInterface.BUTTON_POSITIVE, "yes", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface arg0, int arg1) { 
          Toast.makeText(getApplicationContext(), 

// 
            "You clicked on yes", Toast.LENGTH_SHORT).show(); 

} 
        }); 
+0

をお試しください –

1
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this); 
     alertDialogBuilder.setMessage("Message"); 
     alertDialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       // add your work after click 
      } 
     }); 


     AlertDialog alertDialog = alertDialogBuilder.create(); 
     alertDialog.show(); 

以下のようなパラメータとしてこれを追加するには、alt.setButtonに最初のパラメータとしてDialogInterface.BUTTON_POSITIVEを追加するのを忘れ。

0

本当にありがとうございました。この



    public static void openAlertDialog(final Activity context, final String message) { 
      if (isValueNull(message)) { 
       return; 
      } 

      new AlertDialog.Builder(context).setTitle(R.string.app_name).setMessage(message).setCancelable(false) 
        .setPositiveButton("yes", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          Toast.makeText(getApplicationContext(), 

    // 
             "You clicked on yes", Toast.LENGTH_SHORT).show(); 

         } 
        }).create().show(); 
     } 

関連する問題