1.重复执行SimpleDateFormate导致的,java.lang.IllegalArgumentException: Bad class: class java.lang.String 问题:
既然传入的begin、end已经是规范格式,就不要再 format.format(begin);了!
/** * 计算两个日期之间相差多少天 * * @param begin 2016-05-01 12:00 * @param end 2016-06-01 12:00 * @return String[] [0]day, [1]hour, [2]minute */ public static String[] getDifferMinute(String begin, String end) { L.w("begin: " + begin + " end: " + end); // 一天有(24*60*60*1000)毫秒 long nd = 1000 * 24 * 60 * 60; long nh = 1000 * 60 * 60; long nm = 1000 * 60; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //Bug //Caused by: java.lang.IllegalArgumentException: Bad class: class java.lang.String // String fromDate = format.format(begin); // String toDate = format.format(end); long from = 0, to = 0; try { from = format.parse(begin).getTime(); to = format.parse(end).getTime(); // 获得两个时间的毫秒时间差异 long diff = to - from; // 计算差多少天 long day = diff / nd; // 计算差多少小时 long hour = diff % nd / nh; // 计算差多少分钟 long min = diff % nd % nh / nm; return new String[]{String.valueOf(day), String.valueOf(hour), String.valueOf(min)}; } catch (ParseException e) { e.printStackTrace(); } return null; }
2.ViewStub设置setLayoutResoure之后 inflate,会自动销毁,并将视图交给父布局管理。所以不能把几个ViewGroup交给同一个ViewStub去管理!很坑!
3.Spinner控件调用 setOnItemSelectedListener 会自动执行一次select方法,通过调用 spinnerDutyPerson.setSelection(0, true); 屏蔽:
//禁止OnItemSelectedListener自动调用 spinnerDutyPerson.setSelection(0, true); //放到TagContainer里 spinnerDutyPerson.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (cjExecutorNames.size() > 0) { List<String> tags = tagContainer.getTags(); tags.add(cjExecutorNames.get(position)); LinkedHashSet<String> set = new LinkedHashSet<>(tags); tags.clear(); tags.addAll(set); tagContainer.setTags(tags); } } @Override public void onNothingSelected(AdapterView<?> parent) { } });
4.Predicate 过滤:
private Predicate predicateString(String string) { Predicate ss = (s) -> s.toString().equals(string); return (s) -> s.toString().equals(string); }
5.List去重:有序LinkedHashSet、无序HashSet ,Very Good !亲测有效,可以过滤掉 List<String> 中重复的字符串:
List<String> tags = tagContainer.getTags(); L.d("size: " + tags.size()); if (tags.size() > 0) { // tags.stream().distinct().collect(Collectors.toList());//java8 LinkedHashSet set = new LinkedHashSet(tags); tags.clear(); tags.addAll(set); L.d("distinct size: " + tags.size()); } else { T.showLong("请添加联系人"); return; }
去重对象:
//未选中,需要HashSet去重,确定之后做即可 HashSet<CJExecutorEntity> set = new HashSet<>(); for (CJExecutorEntity bean : tempStates) { set.add(bean); } tempStates.clear(); tempStates.addAll(set);