现在全面负责公司android 产品的开发与维护,压力还真不小。因为产品多,android开发技术人员少。很多需要我亲力亲为。这里记录一下日常遇到的小知识。

1、actionbarsherlock框架,标题栏返回处理

//去掉app图标显示getSupportActionBar().setDisplayShowHomeEnabled(false);actionbarsherlock框架标题栏显示返回图标// 添加返回按钮getSupportActionBar().setDisplayHomeAsUpEnabled(true);

2、androidArrayList排序

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); }



更多相关文章

  1. 【Android】 使用okhttp实现注册登录功能(与服务器端)
  2. Python String 的replace()与List的remove()
  3. android fastjson使用方法 fastjson教程
  4. 【Android(安卓)Developers Training】 11. 支持不同语言
  5. Android正则表达式
  6. Android(安卓)2018最新验证手机号正则表达式
  7. 布局添加下划线
  8. android Map遍历的四种方式
  9. Android(安卓)遍历Hashmap里面的key 和value

随机推荐

  1. 在Android程序代码中实现软件安装和卸载
  2. import小伙伴项目后 关于修改gradle插件
  3. Android(安卓)JetPack-ViewModel初见
  4. (三) 搭建cocos2d-x-android环境 Windows
  5. 新版Eclipse中关联查看Android(安卓)源代
  6. Android(安卓)MediaPlayer与Http Proxy结
  7. Android(安卓)10 适配攻略
  8. Android天气预报程序(八)
  9. Android(安卓)动画各种实现,包括帧动画、
  10. android 常用adb 和 adb shell 命令