How to change tab style in Android?

You could adjust the tabs via code – here’s an excerpt from my application, but you could also assign themes instead of the background image directly. (I haven’t used a way via xml attributes yet, not sure if that’s available as well somehow). private void initTabs() { tabs = (TabHost) findViewById(R.id.tabhost); tabs.setup(); tabs.setBackgroundResource(R.drawable.bg_midgray); TabHost.TabSpec spec; … Read more

What is the difference between if (NULL == pointer) vs if (pointer == NULL)?

There is no difference. What your professor prefers is called Yoda conditions also see “Yoda Conditions”, “Pokémon Exception Handling” and other programming classics. It is supposed to prevent the usage of assignment(=) by mistake over equality(==) in a comparison, but modern compilers should warn about this now, so this type of defensive programming should not … Read more

How can I programmatically copy all of the style attributes from one DOM element to another

With getComputedStyle, you can get the cssText property which will fetch the entire computed style in a CSS string: var completeStyle = window.getComputedStyle(element1, null).cssText; element2.style.cssText = completeStyle; Unfortunately, getComputedStyle isn’t supported by Internet Explorer, which uses currentStyle instead. Doubly unfortunate is the fact that currentStyle returns null for cssText, so the same method cannot be … Read more

Method Overloading with different return type [duplicate]

The C# specification (section 10.6) states that overloaded members may not differ by only return type and as per http://msdn.microsoft.com/en-us/library/ms229029.aspx As per your question regarding creating parameters simply to support differing return types? I personally believe that is a terrible solution to the problem. Code maintenance will become difficult and unused parameters are a definite … Read more

XSS attacks and style attributes

This does not work due to click-jacking vulnerability. Example: <a href=”http://example.com/attack.html” style=”display: block; z-index: 100000; opacity: 0.5; position: fixed; top: 0px; left: 0; width: 1000000px; height: 100000px; background-color: red;”> </a> Found at: http://www.bioinformatics.org/phplabware/forum/viewtopic.php?id=164 The code would be perfectly validated but it may cause serious damage. So – rule of thumb use very strict white list … Read more

Should a collection of constants be placed in a class or interface?

If they have strong connections, then I’d put them in an enum: public enum Error { ERROR_1(“-1”, “foo went wrong”), ERROR_2(“-2”, “bar went wrong”); private final String id; private final String message; Error(String id, String message) { this.id=id; this.message=message; } public String getId() { return id; } public String getMessage() { return message; } } … Read more

Is concatenating with an empty string to do a string conversion really that bad?

Your arguments are good; this is one of the more expressive areas of the Java language, and the “” + idiom seems well entrenched, as you discovered. See String concatenation in the JLS. An expression like “” + c1 + c2 is equivalent to new StringBuffer().append(new Character(c1).toString()) .append(new Character(c2).toString()).toString() except that all of the intermediate … Read more