码迷,mamicode.com
首页 > 移动开发 > 详细

android 日常迭代与维护总结一

时间:2016-05-20 14:38:48      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

现在全面负责公司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 日常迭代与维护总结一

标签:

原文地址:http://blog.csdn.net/qq_16064871/article/details/51460850

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!