F
F
Fotonick2016-04-16 23:25:08
Android
Fotonick, 2016-04-16 23:25:08

Why are pictures repeated in listfragment?

My listfragment receives the necessary information from the server and then assigns a list adapter

setListAdapter(new OneSingerAdapter(RacesFragment.this, allSingersList));

The adapter loads pictures like this
public class OneSingerAdapter extends BaseAdapter {

    private ArrayList<Object> allSingers;
    private LayoutInflater inflater;

    OneSinger oneSinger;
    Bitmap bmp = null;


    public OneSingerAdapter(RacesFragment racesFragment, ArrayList<Object> allSingers) {
        this.allSingers = allSingers;
        this.inflater = (LayoutInflater) racesFragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return allSingers.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Object getItem(int position) {
        return allSingers.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = inflater.inflate(R.layout.singer_view, parent, false);


        oneSinger = (OneSinger) getItem(position);
        TextView singerName = (TextView) convertView.findViewById(R.id.singerName);
        TextView singerGenres = (TextView) convertView.findViewById(R.id.singerGenres);
        TextView singerAlbunsSongs = (TextView) convertView.findViewById(R.id.singerAlbumsSongs);

        singerName.setText(oneSinger.getSingerName());
        singerGenres.setText(oneSinger.getSingerJanres());

        ImageView singerCover = (ImageView) convertView.findViewById(R.id.singerCover);


        new GetImage((ImageView) convertView.findViewById(R.id.singerCover)).execute();



        singerAlbunsSongs.setText(oneSinger.getSingerAlbums() + " альбомов, " + oneSinger.getSingerTracks() + " песни");

        return convertView;
    }

    private class GetImage extends AsyncTask<Void, Void, Bitmap> {
        ImageView bmImage;

        public GetImage(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(Void... params) {

            String urldisplay = oneSinger.getSingerPicLinkSmall();
            Bitmap mIcon11 = null;

            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {
           bmImage.setImageBitmap(result);
        }
    }
}

For some reason, the result is such a picture.
a7634bf2ae6549d7a58196142967b8b1.png
If you scroll down and back, then the pictures are displayed correctly. But if you scroll down sharply or up sharply, then several performers will have the same picture. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2016-04-17
@onepavel

lucasr.org/2012/04/05/performance-tips-for-android...
square.github.io/picasso
you are not a `middle android developer`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question