Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
android display images from folder sequentially

I have a slight problem. I have 27 images, with filenames img0001 up to img00027, how do I get them to play in sequence? As currently it plays img0001, img00010 -> img00019, img0002 -> img00027.

This is what I have in MainActivity.java to handle the switch between images:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.imageView);

        Field[] drawables = R.drawable.class.getFields();
        for (Field f : drawables) {
            if (f.getName().contains("img"))
                imageArrayList.add(getResources().getIdentifier(f.getName(), "drawable", getPackageName()));
        }
    }


    protected void onStart() {
            super.onStart();
            final Handler handler = new Handler();
            Runnable runnable = new Runnable() {
                int i = 0;

                @Override
                public void run() {
                    imageView.setImageResource(imageArrayList .get(i));
                    Animation fade = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_intervals);
                    imageView.startAnimation(fade);
                    i++;
                    if (i > imageArrayList.size() - 1) {
                        i = 0;
                    }
                    handler.postDelayed(this, 4000); // for interval images
                }
            };
            handler.postDelayed(runnable, 8000); // for initial image
        }

Any help would be appreciated. I have tired with just 9 images, img0001-img0009 and that works fine. I feel it is a filename issue, but unsure of how to fix it.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As you said, it is a filename issue. Files are sorted alphanumerically, you should sort imageArrayList according to your needs. Hence, implementing a Comparator (asked here), you should also consider this.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda