增加了按鈕之后,列表條目不能點擊的原因是:需要把Button的相關屬性設置成這樣
android:focusable="false"
不過在開發過程中,我有個動態獲取圖片并刷新列表的機制,發現每次調用完notifyDataSetChanged()方法之后Button都不能點擊了,后來發現如果有圖片動態加載那么每次都要重新inflate整個列表的條目,所以我干脆重載了notifyDataSetChanged()方法。
/**
* Recycle bitmap resources
*/
public void recycleBitmapRes() {
if (mConvertViews != null && !mConvertViews.isEmpty()) {
Collection<View> views = mConvertViews.values();
mConvertViews.clear();
for (View view : views) {
ImageView icon = (ImageView) view.findViewById(R.id.imgIcon);
if (icon != null) {
if (icon.getDrawable() != null && icon.getDrawable() instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) icon.getDrawable()).getBitmap();
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
}
}
}
}
}
@Override
public void notifyDataSetChanged(){
//Avoiding that buttons cannot be pressed
Utils.LogI("GameListAdapter", "notifyDataSetChanged");
recycleBitmapRes();
super.notifyDataSetChanged();
}
---------------------------------------------------------
專注移動開發
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2011-03-19 17:03
TiGERTiAN 閱讀(10397)
評論(0) 編輯 收藏 所屬分類:
Android