Android: integer from xml resource

Yes it is possible, it would look like this: Create an xml resources file in the folder /res/values/ called integers.xml. You are free to give it any name as you want, but choose one that is obvious. In that resources file, create your integer values. Your file then looks something like that: <?xml version=”1.0″ encoding=”utf-8″?> … Read more

Android XXHDPI resources

According to the post linked in the G+ resource: The gorgeous screen on the Nexus 10 falls into the XHDPI density bucket. On tablets, Launcher uses icons from one density bucket up [0] to render them slightly larger. To ensure that your launcher icon (arguably your apps most important asset) is crisp you need to … Read more

findViewById() returns null for Views in a Dialog

Calling findViewById() will search for views within your Activity’s layout and not your dialog’s view. You need to call findViewById() on the specific View that you set as your dialog’s layout. Try this private void initSearch() { AlertDialog.Builder searchDialog = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); searchDialog.setTitle(“Search Photos”); searchDialog.setMessage(“Specify tag and value…”); // R.layout.search_dialog is … Read more

format statement in a string resource file

You do not need to use formatted=”false” in your XML. You just need to use fully qualified string format markers – %[POSITION]$[TYPE] (where [POSITION] is the attribute position and [TYPE] is the variable type), rather than the short versions, for example %s or %d. Quote from Android Docs: String Formatting and Styling: <string name=”welcome_messages”>Hello, %1$s! … Read more

Lint: How to ignore ” is not translated in ” errors?

Android Studio: “File” > “Settings” and type “MissingTranslation” into the search box Eclipse: Windows/Linux: In “Window” > “Preferences” > “Android” > “Lint Error Checking” Mac: “Eclipse” > “Preferences” > “Android” > “Lint Error Checking” Find the MissingTranslation line, and set it to Warning as seen below:

Load dimension value from res/values/dimension.xml from source code

In my dimens.xml I have <dimen name=”test”>48dp</dimen> In code If I do int valueInPixels = (int) getResources().getDimension(R.dimen.test) this will return 72 which as docs state is multiplied by density of current phone (48dp x 1.5 in my case) exactly as docs state : Retrieve a dimensional for a particular resource ID. Unit conversions are based … Read more