Display Toast from within static method in Android -
i wish display toast screen when condition met within static method shown below:
public static void setauth(string a) { string[] nameparts1; if (a.trim().isempty()) { author = "author's name"; firstinit1 = "initial"; surname1 = "surname"; } if (a == 'x') { toast ifx = toast.maketext(getapplicationcontext(), "please enter name in correct format.", toast.length_short); ifx.show(); } }
however gives me error: 'cannot make static reference non-static method getapplicationcontext() type contextwrapper'.
hopefully have provided enough information here. appreciated!
pass context in parameter (in call, use getapplicationcontext() input) , in static function, use context:
public static void setauth(string a, context context) { ... toast ifx = toast.maketext(context, "please enter name in correct format.", toast.length_short); ... }
and in function call
setauth("some string",getapplicationcontext());
Comments
Post a Comment