Johan Schoeman Expert Licensed User Longtime User Apr 19, 2015 #1 The below code compiles when included in the main activity of a B4A project. But when added to a B4A class it complains about getResources(); How do I get around this? Code: Copy public int dp2px(int dip) { Resources resources = getResources(); int px = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics())); return px; }
The below code compiles when included in the main activity of a B4A project. But when added to a B4A class it complains about getResources(); How do I get around this? Code: Copy public int dp2px(int dip) { Resources resources = getResources(); int px = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics())); return px; }
thedesolatesoul Expert Licensed User Longtime User Apr 19, 2015 #2 Try getContext().getResources() ? Upvote 0
Johan Schoeman Expert Licensed User Longtime User Apr 20, 2015 #3 Thanks. This solved it: Code: Copy public int dp2px(int dip) { Resources resources = BA.applicationContext.getResources(); int px = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics())); return px; } Last edited: Apr 20, 2015 Upvote 0
Thanks. This solved it: Code: Copy public int dp2px(int dip) { Resources resources = BA.applicationContext.getResources(); int px = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics())); return px; }