接入騰訊bugly高德地圖報(bào)錯(cuò)
[java.lang.NullPointerException]
Attempt to invoke virtual method 'com.amap.api.maps.UiSettings com.amap.api.maps
只有一個(gè)空指針卻沒有其他提示贱傀,我估計(jì)是libs下的jni庫的問題颊艳,為了趕進(jìn)度,這里簡單把bugly去掉,之后高德地圖正常邀跃。
嵌套的子fragment按鈕設(shè)置點(diǎn)擊背景無效
剛開始我以為是嵌套的子fragment問題,搞了半小時(shí)熊户,后來發(fā)現(xiàn)必須要在fragment里把這個(gè)按鈕的點(diǎn)擊事件寫上才有點(diǎn)擊效果途事,真尼瑪莫名其妙啊验懊,以前不這樣啊擅羞,世界變化的太快尸变!
嵌套子fragment使用viewpage不顯示
因?yàn)閑xtends FragmentPagerAdapter時(shí),傳遞的FragmentManager是父節(jié)點(diǎn)的减俏,改為getChildFragmentManager()即可
重寫equals和hashCode函數(shù)后召烂,Arraylist調(diào)indexOf(object)或者contains(object)無效
場景:
public class ContactsBean implements Serializable {
public String name;
public String number;
public String sort;
public ContactsBean() {
}
public ContactsBean(String name, String number, String sort) {
this.name = name;
this.number = number;
this.sort = sort;
}
@Override
public String toString() {
return "ContactsBean{" +
"name='" + name + '\'' +
", number='" + number + '\'' +
", sort='" + sort + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if(null == o)return false;
if (o instanceof String){
String thatNumber = (String) o;
return number.equals(thatNumber);
}else if(o instanceof CallLogBean){
CallLogBean callLogBean = (CallLogBean) o;
if(null == callLogBean.number)
return false;
return callLogBean.number.equals(number);
}else if(o instanceof ContactsBean){
ContactsBean that = (ContactsBean) o;
if(null == that.number)
return false;
return that.number.equals(number);
}
return false;
}
@Override
public int hashCode() {
return number != null ? number.hashCode() : 0;
}
}
拿ContactsBean和String來對(duì)比,因?yàn)橐袛嚯娫捥?hào)碼和該對(duì)象的電話號(hào)碼是否一致娃承。這時(shí)候調(diào)用Arraylist調(diào)indexOf(object)或者contains(object)無效奏夫∨屡瘢看一下源碼
public boolean contains(Object o) {
return indexOf(o) >= 0;
}
最終去看indexOf
public int indexOf(Object o) {
if (o == null) {
for (int i = 0; i < size; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = 0; i < size; i++)
if (o.equals(elementData[i]))
return i;
}
return -1;
}
關(guān)鍵就在
if (o.equals(elementData[i]))
傳的Object是String,那么這里會(huì)調(diào)用String的equals函數(shù)酗昼,解決辦法就是不要用Arraylist自帶函數(shù)廊谓,把equals函數(shù)的兩端調(diào)換一下位置即可。
for(int i=0;i<mAllContacts.size();i++){
if(mAllContacts.get(i).equals(number)){
name = mAllContacts.get(i).name;
break;
}
}
RelativeLayout麻削、LinearLayout點(diǎn)兩下才有onClick事件問題
因?yàn)樵趯傩岳镌O(shè)置了
android:clickable="true"
android:focusableInTouchMode="true"
這兩個(gè)屬性有沖突蒸痹,去掉android:focusableInTouchMode="true"即可。
另外在background里設(shè)置的點(diǎn)擊效果drawable文件里呛哟,要把a(bǔ)ndroid:state_focused="true"去掉叠荠,只保留android:state_pressed="true",否則點(diǎn)擊效果不出來扫责。