android 日常迭代與維護總結一

來源:互聯網
上載者:User

標籤:

現在全面負責公司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 日常迭代與維護總結一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.