The image (in this moment just one for one specified country), when I scroll the listview appears in some rows, when should appear in just one specified row.
Example: in the row "france", appear the flag of france, but then, the same flag appears in other rows. Not in all rows. At the moment, I'm only testing with the flag of france.
public class MyListAdapter extends SimpleCursorAdapter{
private Cursor cur;
private Context context;
private SQLiteDatabase db;
private static final String ASSETS_DIR = "images/";
private String Flag;
public MyListAdapter (Context context, Cursor c, SQLiteDatabase db) {
super(context, R.layout.countries_list_item, c, new String[] {}, new int[] {});
this.cur=super.getCursor();
this.context = context;
this.db=db;
}
private class ViewHolder {
TextView txtTitle, txtDate;
ImageView countryIcon;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.countries_list_item, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.lastName);
holder.txtDate = (TextView) convertView.findViewById(R.id.firstName);
holder.countryIcon = (ImageView) convertView.findViewById(R.id.country_icon);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
this.cur.moveToPosition(position);
holder.txtTitle.setText(this.cur.getString(this.cur.getColumnIndex("CountryID")));
holder.txtDate.setText(this.cur.getString(this.cur.getColumnIndex("Country")));
Flag =(this.cur.getString(this.cur.getColumnIndex("CountryImage")));
Flag=Flag.trim();
// Set country icon usign File path
try {
String imgFilePath = ASSETS_DIR +""+Flag;
Bitmap bitmap = BitmapFactory.decodeStream(this.context.getResources().getAssets().open(imgFilePath));
holder.countryIcon.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
return convertView;
}
}