1.如何求兩個整數的百分比
- int currentindex = 55;
- int totalcount = 66;
- NumberFormat nf = NumberFormat.getPercentInstance();
- final String persent = nf.format(((float)currentindex/(float)totalcount));
2.從一個鏈接中獲取域名
- String url = "http://blog.csdn.net/zuolongsnail";
- Pattern p = Pattern.compile(
- "(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)",
- Pattern.CASE_INSENSITIVE);
- Matcher matcher = p.matcher(url);
- matcher.find();
- System.out.println(matcher.group());
3.顯示年月日時分秒星期
- Date date = new Date();
- SimpleDateFormat dateformat = new SimpleDateFormat(
- "yyyy年MM月dd日 HH時mm分ss秒 E");
- String dateStr = dateformat.format(date);
- System.out.println(dateStr);
4.顯示年月日時分秒毫秒
- Date date = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH時mm分ss秒SSS");
- String dateStr = sdf.format(date);
- System.out.println(dateStr);
5.發送多條短信
- PendingIntent sentPI = PendingIntent.getBroadcast(context,
- System.identityHashCode(intent), intent, 0);
- SmsManager smsManager = SmsManager.getDefault();
- // 超過70字分段發送
- if (text.length() > 70) {
- ArrayList<PendingIntent> sentPIs = new ArrayList<PendingIntent>();
- sentPIs.add(sentPI);
- smsManager.sendMultipartTextMessage(destAdress, null,
- smsManager.divideMessage(text), sentPIs, null);
- } else {
- smsManager.sendTextMessage(destAdress, null, text, sentPI, null);
- }
6.屏蔽多點觸摸
- android:splitMotionEvents="false"