The first parameter to the
makeText
call should be an
Activity
instance, in your case it looks like you've copied a click-handler that was previously an anonymous type inside
MainActivity
. But since
Toaster
is not part of
MainActivity
you could try passing the
Activity
in to the
Toaster
.
Change your code to;
public class Toaster implements OnClickListener {
private final MainActivity mainActivity;
public Toaster(final MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
@Override
public void onClick(View clickedButton) {
final String greetingText = "Hello from Android!";
final Toast tempMessage = Toast.makeText(mainActivity, greetingText, Toast.LENGTH_SHORT);
tempMessage.show();
}
}
and make sure to pass the instance of
MainActivity
to
Toaster
when calling it's constructor.
Hope this helps,
Fredrik