做android有四年了。一直没有写博客的习惯,平时看资料、工作中遇到的问题都习惯简要的写到word里面。现在决定慢慢写到博客里来。
1、adapter.notifyDataSetChanged(),用过的应该都知道,这个方法必须要在主线程中执行,否则会抛异常。但是某些情况下,即使在主线程调用仍然会出问题:java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.也就是说。adapter里面的数据的变更也必须要在UI线程里。
2、map的key存的是自定义的类:map={A, "value_1"},但是取的时候:map.get(A),确取不到。纠结了很久,最后一步一步断点才找到问题:存在map里的A,和外部变量的A的hashcode不同了(map的get方法是通过判断key的hashcode来识别的)。解决方法就是要重写A的hashcode()方法