It is necessary to display a list of animated gifs. To work with the list I use an adapter. The class is shown below:

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; } } 

When forming the list, gifs appear, but are not animated. Maybe it's in the final modifier before gifImageView? RetreiveByteArray class:

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; } } 

    1 answer 1

    Start animation is the built-in android method of the view, which starts the specified animation of movements, rotations, etc. Perhaps if your component has such a method and it has to play the gif, then startAnimation is simply not redefined. Look at the implementation of this method in GifImageView. If none of the reasons above solve the problem, then the error is already somewhere in the GifImageView and there may already be anything