jeudi 24 décembre 2015

Android - ListView recycle cannot change the Viewholder value from Updated sqlite database

I'm just running into the ListView recycle using the custom adapter.
What I actually do is I have One adapter for one Listview....Listview updated on new incoming messeages,status...etc.,
Initially,I load the messages,status from the sqlite database and add those items to the listview.Secondly,communicate with the server and updated the listview with those new messages and I also insert those new ones into sqlite database

You guys have used whatsapp messenger,their you initailly loaded with Low quality Image and when I downloaded it...The imageView will be loaded with high quality image...Likewise I do the same here...

Everything is fine,there..But,after I clicked download button and HD image download and successfully sat on the ImageView....

But when I scroll up the old LQ image loads up instead of HQ....When I try closing up the application and opens again..Its load perfectly,even when you scroll.....

The problem is when I dynamically Update I sqldatabase Image with base64 Bitcode....It load the previous Low Quality Bitcode..Not the one we just downloaded it...

Here's my getview code:

static Context context;
int layoutResourceId;
ArrayList<FeedDataType> data = new ArrayList<FeedDataType>();
UserHolder holder;
static String user_id;
File path;

public View getView(int position, View convertView, ViewGroup parent) {
    holder = null;
    View row = convertView;
    Log.e("getview:",position+" "+convertView);
    if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, null);

        holder = new UserHolder();
        holder.full_name = (TextView) row.findViewById(R.id.UserName);
        holder.status = (TextView) row.findViewById(R.id.status);
        holder.time = (TextView) row.findViewById(R.id.time);
        holder.date = (TextView) row.findViewById(R.id.date);
        holder.likeCount = (TextView) row.findViewById(R.id.likeCount);
        holder.commentCount = (TextView) row
                .findViewById(R.id.commentCount);
        holder.profile_img = (ImageView) row.findViewById(R.id.profileImg);
        holder.status_img = (ImageView) row.findViewById(R.id.image);
        holder.status_img_box = (RelativeLayout) row
                .findViewById(R.id.imageContainer);
        holder.downloadIcon = (ImageView) row
                .findViewById(R.id.downloadIcon);
        holder.like_ = (LinearLayout) row.findViewById(R.id.like);
        holder.comment_ = (LinearLayout) row.findViewById(R.id.comment);
        row.setTag(holder);

    } else {
        holder = (UserHolder) row.getTag();
    }

    final FeedDataType user = data.get(position);

    // if (user != null) {

    String StatusIMg;

    if (user.getStatusImgURL() != null) {
        if (user.getStatusImgURL().trim().length() > 5) {
            Log.e("Img Donwloaded",
                    user.getStatus() + " ... " + user.getImgDownloaded());
            if (isValidURL(user.getStatusImg()) == true) {
                if (user.getImgDownloaded().matches("1")) {
                    StatusIMg = user.getStatusImg() + ".jpg";
                    holder.downloadIcon.setVisibility(View.GONE);
                } else {
                    StatusIMg = user.getStatusImg() + "_mini.jpg";
                }

                Glide.with(context).load(StatusIMg).skipMemoryCache(true)
                        .centerCrop()
                        .placeholder(R.drawable.placeholder_image)
                        .crossFade().into(holder.status_img);
            } else {
                byte[] data = Base64.decode(user.getStatusImg(),
                        Base64.DEFAULT);
                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,
                        data.length);
                holder.status_img.setImageBitmap(bitmap);

            }
                if (user.getImgDownloaded().matches("1")) {
                    holder.downloadIcon.setVisibility(View.GONE);
                } else {
                    holder.downloadIcon.setVisibility(View.VISIBLE);
                }
            holder.status_img_box.setVisibility(View.VISIBLE);

        } else {
            holder.status_img_box.setVisibility(View.GONE);
        }
    } else {
        holder.status_img_box.setVisibility(View.GONE);
    }
    holder.full_name.setText(user.getName());
    holder.status.setText(user.getStatus());
    holder.time.setText(user.getTime());
    holder.date.setText(user.getDate());
    holder.likeCount.setText(user.getLike());
    holder.commentCount.setText(user.getComment());

    holder.downloadIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            RelativeLayout rl = (RelativeLayout) v.getParent();
            ImageView imageView = (ImageView) rl.findViewById(R.id.image);
            new ImageDownloaderTask(context).execute(imageView, v,
                    user.getStatusImgURL() + ".jpg", user.getStatusId());
        }
    });

    return row;

}

Thanks In advance and Merry X-mas to all

Aucun commentaire:

Enregistrer un commentaire