android - findViewById inside a Static Method -
i have static method:
public static void displaylevelup(int level, context context) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view layout = inflater.inflate(r.layout.custom_level_coast, (viewgroup) findviewbyid(r.id.toast_layout_root)); // row textview text = (textview) layout.findviewbyid(r.id.toasttext); text.settext("this custom toast"); toast toast = new toast(context); toast.setgravity(gravity.center_vertical, 0, 0); toast.setduration(toast.length_long); toast.setview(layout); toast.show(); toast.maketext(context, string.valueof(level), toast.length_short) .show(); }
however, can't figure out how firstfindviewbyid
play nice says non-static method. understand why says that, there must workaround? passed context
method couldn't work them out together.
one thing can make view class wide variable , use that. dont recommend doing work if need quick , dirty.
passing in view parameter preferred way
Comments
Post a Comment