紀錄一下覺得寫得很清楚的文章。
http://jim690701.blogspot.tw/2012/12/androidspinner.html
Java Regular Expression的學習筆記 [精華]public static int CheckPassword(String resource) { int length = resource.length(); if (length >= 12 || length < 8) return 0; try { int strong = 0; for (int i = 0; i < length; i++) { if (resource.charAt(i) >= 'a' && resource.charAt(i) <= 'z') { strong++; break; } } for (int i = 0; i < length; i++) { if (resource.charAt(i) >= 'A' && resource.charAt(i) <= 'Z') { strong++; break; } } for (int i = 0; i < length; i++) { if (resource.charAt(i) >= '0' && resource.charAt(i) <= '9') { strong++; break; } } for (int i = 0; i < length; i++) { if (!((resource.charAt(i) >= 'a' && resource.charAt(i) <= 'z') || (resource.charAt(i) >= 'A' && resource.charAt(i) <= 'Z') || (resource.charAt(i) >= '0' && resource.charAt(i) <= '9'))) { strong++; break; } } return strong; } catch (Exception e) { } // 例外 return 0;}
參考了Patterns裡的EMAIL_ADDRESSpublic static boolean isValidPassword(String password){ return Pattern.compile("^(?=.*[a-zA-Z]+)(?=.*\\d+)[a-zA-Z0-9]{8,12}$") .matcher(password).matches();}
new MyFragment()
和
MyFragment.newInstance()
有什麼不同?哪個比較好?
答: 使用
newInstance()比較好,兩個原因:What is the difference betweennew MyFragment()
andMyFragment.newInstance()
? Should I prefer one over the other?
newInstance()
method is a "static factory method," allowing us to initialize and setup a new Fragment
without having to call its constructor and additional setter methods. Providing static factory methods for your fragments is good practice because it encapsulates and abstracts the steps required to setup the object from the client. For example, consider the following code:public class MyFragment extends Fragment {
/**
* Static factory method that takes an int parameter,
* initializes the fragment's arguments, and returns the
* new fragment to the client.
*/
public static MyFragment newInstance(int index) {
MyFragment f = new MyFragment();
Bundle args = new Bundle();
args.putInt("index", index);
f.setArguments(args);
return f;
}
}