Необходимо вывести список анимированных гифок. Для работы со списком использую адаптер. Класс приведён ниже:
class GifsListAdapter extends ArrayAdapter{
private final Activity context;
ArrayList<GifInfo> gifInfoList;
public GifsListAdapter(Activity context, ArrayList<GifInfo> gifInfoList) {
super(context, R.layout.gifs_list, gifInfoList);
this.context = context;
this.gifInfoList = gifInfoList;
}
@SuppressLint("StaticFieldLeak")
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.gifs_list, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.gifNameTextView);
txtTitle.setText(gifInfoList.get(position).getGifName());
final GifImageView gifImageView = (GifImageView) rowView.findViewById(R.id.giphyImageView);
new RetrieveByteArray(){
@Override
protected void onPostExecute(final byte[] bytes) {
super.onPostExecute(bytes);
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
}
}.execute(gifInfoList.get(position).getGifUrl());
return rowView;
}
}
При формировании списка гифки появляются, но не анимируются. Может дело в модифкаторе final перед gifImageView ? Класс RetreiveByteArray:
class RetrieveByteArray extends AsyncTask {
@Override
protected byte[] doInBackground(String... strings) {
try{
URL url = new URL(strings[0]);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
if(urlConnection.getResponseCode()== 200)
{
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int read;
byte[] data = new byte[10240];
while((read = in.read(data, 0, data.length)) != -1){
buffer.write(data, 0, read);
}
buffer.flush();
return buffer.toByteArray();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}