Изображение (в данный момент только одно для одной указанной страны), когда я прокручиваю список, появляется в нескольких строках, когда должно появляться только в одной указанной строке.
Пример: в строке «Франция» появляется флаг Франции, но затем этот же флаг появляется в других строках.Не во всех рядах.На данный момент я тестирую только с флагом Франции.
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;
}
}