2015-09-11

[Android] 如何改變DatePicker的Divider的顏色 (How to change the divider color of the DatePicker)


這是一個可以自己從xml指定Divider的顏色的DatePicker

可以把像下圖這樣的Spinner DatePicker的Divider從藍色換成別的自己指定的顏色
We can change the divider color of DatePicker from blue to any other color you want.



首先要先在resource的drawable當中加入一個shape
把"THE_COLOR_YOU_WANT"換成你想要的顏色

2015-08-04

[Android] 字串比較的兩種方式的比較 Comparison of Two ways of String Comparison: TextUtils.equals() and String.equals()


字串比較的兩種方式的比較
Comparison of Two ways of String Comparison:

TextUtils.equals() and String.equals()

[Android] 檢查參數Check arguments: Preconditions.checkArgument(), checkNotNull()



http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html

[Java] String.valueOf() 和 Integer.toString(), Long.toString, Double.toString的差異. 為何String.valueOf()比較好?Why String.valueOf() is better than toString()?



為何String.valueOf()比 Integer.toString(), Long.toString, Double.toString好?
Why String.valueOf() is better than toString()?

1. If a value is null.

toString() would throw NullPointerException.
String.valueOf() would return a String "null".

當輸入值為null, String.valueOf()不會發生Exception.

2.
像這樣的一個function
public String example1(int num, boolean boo) {
 return Integer.toString(num) + Boolean.toString(boo);
}

如果參數的type改變了, 那麼implemention就也要跟著改變
If the type of num and boo is changed, the the implementation have to change depends on the type of num and boo.

但如果使用String.valueOf() 那麼就不用改變implementation了

像下面這個function, 就算參數的type一直改, function implementation也都不用改
You don't have to change implementation when the type of num and boo is changed.

public String example2(int num, boolean boo) {
  return String.valueOf(num) + " " +  String.valueOf(boo);
 }

3.