1
我在設置圖像視圖上的drawable時遇到了ArrayAdapter類中的問題。首先它不會出現,只有當我滾動列表中。將imageDrawable設置爲ImageView不顯示
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item, parent, false);
holder = new Holder();
convertView.setTag(holder);
loadUI(holder, convertView);
} else {
holder = (Holder) convertView.getTag();
}
final MyObject obj = getItem(position);
if(obj != null) {
setAvatar(obj.getModerator(), holder);
}
return convertView;
}
private void setAvatar(Moderator moderator, Holder holder) {
String avatar = moderator.getAvatar();
if (avatar != null) {
holder.icon.setImageUrl(avatar, ImageCacheManager.getInstance().getImageLoader());
} else {
TextDrawable drawable = TextDrawable.builder()
.beginConfig()
.width(60)
.height(60)
.endConfig()
.buildRoundRect(moderator.getAlias() != null ? moderator.getAlias() : "G", Color.BLUE, 8);
Log.d(Constants.TAG, "Drawable: " + drawable);
holder.icon.setImageDrawable(drawable);
}
}
至於TextDrawable我使用這個開源類:https://github.com/amulyakhare/TextDrawable/blob/master/library/src/main/java/com/amulyakhare/textdrawable/TextDrawable.java
Holder類:
static class Holder {
TextView authorNameTxt;
TextView msgTxt;
TextView timeTxt;
com.pubble.mod.utils.CircleImageView icon;
com.android.volley.toolbox.NetworkImageView msgPhoto;
}
基本上它填充NetworkImageView,但只有當我滾動,我不明白爲什麼。
發表您的holder類 – Jas
什麼是'item'在'如果(項目!= NULL)'? –
對不起,我改變了變量的名字。現在編輯。 – user1140656