Comments (9)
Hi tai1135,
You should post whole adapter code because snippet you provided is not enough.
Regards,
Dragan
from android-smart-image-view.
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.
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.
- 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.
Was this issue ever resolved?
from android-smart-image-view.
@TeknoloGenie : Not yet, long time not work on it.
from android-smart-image-view.
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.
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.
@TeknoloGenie : Have you posted the Solution for this? can you please share it on this thread?
two solutions I found for it were,
- adding ".refreshDrawableState();" on the view. this makes the image appear and disappear. which makes it not a good solution.
- 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)
- not loading image on smart image view progmatically
- Still OutOfMemory issues
- Some images are loaded as ColorDrawable while some as BitmapDrawable
- Crash application HOT 1
- I build a HTTP server in local,then use SmartImageView.setImageUrl(String url)
- Error when saving cache file for very long URL: ENAMETOOLONG (File name too long)
- Out of memory HOT 1
- Loaded Images Mix Up While Scrolling In List View Adapter HOT 5
- develop to get facebook image HOT 1
- Very choppy scrolling in a ListView with SmartImageView
- How to set a progressloader for Images in ListView
- geographique card HOT 1
- Progressive download feature
- Need zoom capability
- Update cached image
- Regard to APK File
- Gradle dependencie
- Cache removal control
- Still supported
- Crash Aplicattion HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-smart-image-view.