2012-01-11 17 views
13

Bir onClickListener'dan bir AlertDialog başlatmaya çalışıyorum ama şu hatayı alıyorum.AlertDialog in onClickListener

The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined 

Bunu nasıl düzelteceğini bilen var mı?

 mRecordButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      new AlertDialog.Builder(this) 
      .setTitle("Cast Recording") 
      .setMessage("Now recording your message") 
      .setPositiveButton("Save", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Log.d("AlertDialog", "Positive"); 
       } 
      }) 
      .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Log.d("AlertDialog", "Negative"); 
       } 
      }) 
      .show(); 
     } 
    }); 

cevap

29

Değişim

new AlertDialog.Builder(YourActivity.this); 

yapıcı & OnclickListner is not a Context type böylece Faaliyet nesneyi kullanmak bir Bağlam türü ihtiyacı olmasıdır için bu hat

new AlertDialog.Builder(this); 

. Ben yardımcı olur umarım

.. new AlertDialog.Builder(this) yılında

0

, this dinleyici değil, dış sınıf örneğine bahsediyor.

İlgili konular