Answer the question
In order to leave comments, you need to log in
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));
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);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question