How does one use Resources.getFraction()?

You specify fractions in XML as so: <item name=”fraction” type=”fraction”>5%</item> <item name=”parent_fraction” type=”fraction”>2%p</item> Where 5% would be 0.05 when actually used. Then: // 0.05f getResources().getFraction(R.fraction.fraction, 1, 1); // 0.02f getResources().getFraction(R.fraction.parent_fraction, 1, 1); // 0.10f getResources().getFraction(R.fraction.fraction, 2, 1); // 0.10f getResources().getFraction(R.fraction.fraction, 2, 2); // 0.04f getResources().getFraction(R.fraction.parent_fraction, 1, 2); // 0.04f getResources().getFraction(R.fraction.parent_fraction, 2, 2); As you can … Read more

How can I convert the android resources int to a string. eg.: android.R.string.cancel?

Simply use Context#getString(): String string = getString(android.R.string.cancel); I’ve already tried this approach but with no success… I’ve a class: public class MyDialogFragment extends DialogFragment { A DialogFragment is not a subclass of Context, so you need to get access to a valid one (like your Activity’s). Use this: String string = getActivity().getString(android.R.string.cancel); Or as your … Read more

Android resource selection layout- and values- inconsistencies

I’m sure you’re dealing with resource precedence used for selection. If you provide folders: layout-sw600dp-* values-large-* values-sw600dp-* Android is not obliged to match values selection folder to those of layout, rather it uses same precedence logic separately for layout and separately for values folder. You can learn about this selection algorithm here: http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch

What is the concept behind R.java?

Biggest advantage is in Localization and Providing alternate resources for different screen sizes. e.g you can have a String resource R.string.myname this could be a defined in english in /values-en/strings.xml and in spanish in /values-es/strings.xml System will take care or picking up the right file depending on the locale you just need to use @string/myname … Read more

How to read custom dimension attribute from java code

A few things to say : first you need a xml name space declaration line at the top of your xml, exactly in the same way as you do with android xmlns : xmlns:foo=”http://schemas.android.com/apk/res-auto” then you need to prefix valueTextSize with your xmlns : foo:valueTextSize=”40sp” After that, it’s not a very good idea to get … Read more

Plural definition is ignored for zero quantity

According to the documentation : The selection of which string to use is made solely based on grammatical necessity. In English, a string for zero will be ignored even if the quantity is 0, because 0 isn’t grammatically different from 2, or any other number except 1 (“zero books”, “one book”, “two books”, and so … Read more

Binary XML file line #1: invalid drawable tag vector

Documentation about Vector Graphics says: Android 4.4 (API level 20) and lower doesn’t support vector drawables. With Support Library you have backward-compatibility using the attribute app:srcCompat, but it is not backported for android:drawableRight. The solution is to keep using .PNG files for those cases or try to set it by code.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)