Displaying Images Dynamically
02:34 02 Feb 2016

I am using the following code to display images from drawable folder. But now i want to display pictures dynamically.Every time a new image is added to the drawable folder i don't want go again in the code and add it in the array it should automatically increment and get displayed. Any Idea how should I go about this.Just started working on Android.

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.widget.ImageView;
import android.app.Service;
import android.os.Handler;


 public class MainActivity extends AppCompatActivity {

 private static ImageView imgView;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imgView = (ImageView) findViewById(R.id.imageView);   

                                                                               final int[] images=images{R.drawable.ic_launcher,

    R.drawable.ic_launcher1,R.drawable.ic_launcher2,etc..};


    final Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        int i=0;
        public void run() {
            imgView.setImageResource(images[i]);
            i++;
            if(i>images.length-1)
            {
                i=0;
            }
            handler.postDelayed(this,5000);  //for interval...
        }

    };
    handler.postDelayed(runnable, 5000); //for initial delay..

 }
java android android-imageview