What is the error (this) in the code

button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(this) .title(R.string.app_name) .show(); } }); 

screen: enter image description here

  • one
    Sorry - Andrei
  • 3
    You probably didn’t have time to investigate your own problem either? Uh ... Want some advice? Change the color scheme to start, this ate a piece of the error message. Or is it just that the error formatting is so weird? ._. - D-side
  • one
    Yes, it seems everything is in place, it is clearly visible that the designer wants the Context , and an anonymous class based on View.OnClickListener . - zRrr
  • four
    If you do not have time to write a good question, I think you should not expect that we will have time to write a good answer. - VladD
  • one
    @ YuriySPb, as always on top))) - Andrew

1 answer 1

MaterialDialog Builder takes Context for input .

You have this - a link to the anonymous class OnClickListener .

You can for example:

 new MaterialDialog.Builder(НазваниеВашегоActivity.this){...} 
  • how to fix??? - Andrei
  • @ Andrei pass an instance of Context , obviously. - D-side
  • @ D-side, what exactly and where to change I am full 0 (((( - Andrei
  • one
    @ Andrew new MaterialDialog.Builder(НазваниеВашегоActivity.this){...} YourActivity.this new MaterialDialog.Builder(НазваниеВашегоActivity.this){...} - Suvitruf