標籤:
現在全面負責公司android 產品的開發與維護,壓力還真不小。因為產品多,android開發技術人員少。很多需要我親力親為。這裡記錄一下日常遇到的小知識。
1、actionbarsherlock架構,標題列返回處理
//去掉app表徵圖顯示getSupportActionBar().setDisplayShowHomeEnabled(false);actionbarsherlock架構標題列顯示返回表徵圖// 添加返回按鈕getSupportActionBar().setDisplayHomeAsUpEnabled(true);
2、android ArrayList排序
public class MyComparator implements Comparator<Student> { public int compare(Student s1, Student s2) { if(s1.getID() > s2.getID()){ return 1; } else if(s1.getID() < s2.getID()) { return -1; } return 0; } }
student的實體類就不貼了,能看懂的。看看怎麼使用吧。
Student s1 = new Student("001", "Jim", "男", 50); Student s2 = new Student("002", "Tom", "男", 70); Student s3 = new Student("003", "Dave", "男", 65); Student s4 = new Student("004", "Peter", "男", 80); Student s5 = new Student("005", "Lucy", "女", 100); //建立集合 ArrayList<Student> list = new ArrayList<Student>(); list.add(s1); list.add(s2); list.add(s3); list.add(s4); list.add(s5); Comparator comparator = new MyComparator();//重要部分 Collections.sort(list, comparator);
3、android 調用系統預設的瀏覽器開啟本地html檔案
Intent intent= new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("file://" + strFilePathName); intent.setData(content_url); intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); mContext.startActivity(intent);AndroidManifest.xml檔案把加到相應activity的<intent-filter>後面就可以了
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> data android:scheme="file" /> </intent-filter>
4、String.split("\\+")的字串分隔特殊情況
srcData[1].split("\\+")的字串分隔的用法,遇到分隔是?(問號),+(加號),*(乘),|(豎線),.(點)等都是逸出字元,必須的加上"\\"。
5、字串提取數字
public static int getStringExtractInt(String string){String regEx="[^0-9]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(string); String strResult = m.replaceAll("").trim();if (strResult.isEmpty() || strResult == "") {strResult = "0";}return Integer.parseInt(strResult);}
6、分割字串提取資料
public static int getStringSpiltToInt(String strSpilt , String string) {String[] result = string.split(strSpilt);if (result[0].isEmpty()|| result[0] == null ) {result[0] = "0";}return Integer.parseInt(result[0]);}
7、分割字串提取資料,返回整型數組
/** * 分割字串提取資料,返回整型數組 * @param strSpilt * @param string * @return int[] */public static int[] getStringSpiltToIntArray(String strSpilt , String string) {String[] result = string.split(strSpilt); int[] nResult = new int[result.length];for (int i = 0; i < result.length; i++) {if (result[i].isEmpty()|| result[i] == null ) {result[i] = "0";}}for (int i = 0; i < nResult.length; i++) {Integer.parseInt(result[i]);}return nResult;}
8、textview加底線
textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //底線textView.getPaint().setAntiAlias(true);//消除鋸齒textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中劃線setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); // 設定中劃線並加清晰 textView.getPaint().setFlags(0); // 取消設定的的劃線
9、cursor遍曆資料表的值
根據列索引遍曆讀取列資料:while(cursor.moveToNext()){//根據列的索引直接讀取 比如第0列的值 String strValue= cursor.getString(0); }
根據列名擷取列索引遍曆讀取列資料:while(cursor.moveToNext()){//根據列名擷取列索引 int nameColumnIndex = cursor.getColumnIndex(“username");String strValue=cursor.getString(nameColumnIndex); }
android 日常迭代與維護總結一