Coder Social home page Coder Social logo

Display wrong image about android-smart-image-view HOT 9 OPEN

loopj avatar loopj commented on July 20, 2024
Display wrong image

from android-smart-image-view.

Comments (9)

dmarjanovic avatar dmarjanovic commented on July 20, 2024

Hi tai1135,

You should post whole adapter code because snippet you provided is not enough.

Regards,
Dragan

from android-smart-image-view.

tai1135 avatar tai1135 commented on July 20, 2024

This is code for Adapter :

package toxter.com.component;

import java.util.ArrayList;
import com.loopj.android.image.SmartImageView;

import toxter.com.R;
import toxter.com.common.AppConfig;
import toxter.com.model.Contact;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.TextView;

public class ListContactAdapter extends ArrayAdapter{
ArrayList currentList;
ArrayList origin_array;
int resource;
Context context;

public ListContactAdapter(Context context, int textViewResourceId, ArrayList<Contact> objects) {
    super(context, textViewResourceId, objects);
    this.context = context;
    resource = textViewResourceId;
    currentList = objects;
    origin_array = (ArrayList<Contact>) currentList.clone();
}

@Override
public Filter getFilter() {
    return arrayFilter;
}

Filter arrayFilter = new Filter() {

    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults filterResults = new FilterResults();

        ArrayList<Contact> data;
        if(constraint != null && constraint.length() != 0) {
            data = new ArrayList<Contact>();
            for (Contact contact : origin_array) {
                if((contact.first_name != null && contact.first_name.toLowerCase().contains(constraint)) || (contact.last_name != null && contact.last_name.toLowerCase().contains(constraint)) || (contact.email != null && contact.email.toLowerCase().contains(constraint))) {
                    data.add(contact);
                }
            }
        } else {
            data = origin_array;
        }

        filterResults.values = data;
        filterResults.count = data.size();

        return filterResults;
    }

    @Override
    protected void publishResults(CharSequence constraint, FilterResults results) {
        ArrayList<Contact> filteredList = (ArrayList<Contact>) results.values;
        if(results != null && results.count > 0) {
            clear();
            for (Contact c : filteredList) {
                add(c);
            }
            notifyDataSetChanged();
        }
    }

};

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View contactView = convertView;

    if (contactView == null) {
        contactView = new ContactView(getContext());
    }

    final Contact contact = currentList.get(position);

    //Display infor in view
    if (contact != null) {
        TextView lblContactName = ((ContactView) contactView).lblContactName;
        TextView lblContactEmail = ((ContactView) contactView).lblContactEmail;
        SmartImageView imgContactImage = ((ContactView) contactView).imgContactImage;

        lblContactName.setText(AppConfig.GetContactFullName(contact.first_name ,contact.last_name));
        lblContactEmail.setText(contact.email);

        String image = "";
        if(contact.image == null || contact.image.isEmpty()) {
            try {
                Integer.parseInt(contact.fb_image);
            } catch (Exception e) {
                image = contact.fb_image ;
            }
        } else {
            image = contact.image;
        } 

        if(image == null || image.isEmpty()) {
            imgContactImage.setImageResource(R.drawable.nophoto);
        } else {
            imgContactImage.setImageUrl(image);
        }


        //set onClick for item
        contactView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Activity activity = (Activity)context;
                Intent returnIntent = new Intent();
                returnIntent.putExtra("contact", AppConfig.gson.toJson(contact));
                activity.setResult(Activity.RESULT_OK,returnIntent);
                activity.finish();
            }
        });
    }

    return contactView;
}    

}

from android-smart-image-view.

dmarjanovic avatar dmarjanovic commented on July 20, 2024

I guess you have valid nophoto.png in your /drawable directory.

Have you checked with debugger or by logging if this line is ever executed
imgContactImage.setImageResource(R.drawable.nophoto) ?

You should always handle all cases in getView() even when contact is null - in that case you should set TextViews to empty string and hide ImageView. In case you don't there will be shown items with some random name/email/image even if contact is null.

from android-smart-image-view.

tai1135 avatar tai1135 commented on July 20, 2024
  • First it executed line : imgContactImage.setImageResource(R.drawable.nophoto).
  • Second is i saw this line executed 4 or more times just for 1 view (1 contact).
  • And the picture still wrong.
  • An additional is first time it good, but when i reload the list (PullToRefreshList) it take the wrong image.

Do you have any ideas ? Thanks a lots.

from android-smart-image-view.

TeknoloGenie avatar TeknoloGenie commented on July 20, 2024

Was this issue ever resolved?

from android-smart-image-view.

tai1135 avatar tai1135 commented on July 20, 2024

@TeknoloGenie : Not yet, long time not work on it.

from android-smart-image-view.

TeknoloGenie avatar TeknoloGenie commented on July 20, 2024

I resolved the issue we were having. Same outcome as you, not sure if the same issue, but i'll post on this tomorrow with a pull request.

from android-smart-image-view.

BuddhaSource avatar BuddhaSource commented on July 20, 2024

We solved this by assigning a default drawable at view, it is kinda hack but never had problem ever since.

from android-smart-image-view.

azhar-bandri avatar azhar-bandri commented on July 20, 2024

@TeknoloGenie : Have you posted the Solution for this? can you please share it on this thread?

two solutions I found for it were,

  1. adding ".refreshDrawableState();" on the view. this makes the image appear and disappear. which makes it not a good solution.
  2. Always creating a new ContactView() (as in above example). But this solution makes the Listview very Slow.

Please share any better robust solution. Thanks!

from android-smart-image-view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.