Android: refresh image Switcher content Based on radioButton choice
<p>My application intend to select image switcher content based on one of two selected radio button. on radio button click, the application does not choose desired option and finally the application crashed.  </p>

<p>The big problem is i want to free the array holding images for the swicher based on the radio button checked. </p>

<p>Also, there are two arrays with image reference to it. i want to delete all the array inside the  gallery and add one of the reference. Here is my code.</p>

<pre><code>public void onCheckedChanged(RadioGroup group, int checkedId) {

    // TODO Auto-generated method stub

    //check which id is selected

    radioCheckedId= checkedId;


    //radio button checked

    switch(radioCheckedId){

        case R.id.radBtnAccident:
</code></pre>

<p>//delete all array
                if (pics.length>0){</p>

<pre><code>                for (int arr=0;arr&lt;pics.length;arr++){

                    pics[arr]=null;

                }
            }

            //populates array

            pics = new Integer[]{ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
                                  R.drawable.e,R.drawable.exit, R.drawable.plan, R.drawable.icon, R.drawable.plan };

            chooseImgArray(pics);

        break;

        case R.id.radBtnOthers:

            //populates other array

            pics = new Integer[]{R.drawable.exit, R.drawable.plan,
</code></pre>

<p>R.drawable.icon, R.drawable.plan,R.drawable.c };</p>

<pre><code>            chooseImgArray(pics);
        break;

    default:

    break;


    }

}

public void chooseImgArray(final Integer[] array){


    iSwitcher = (ImageSwitcher) findViewById(R.id.ImgSwith);

    iSwitcher.setFactory(this);
    iSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
    iSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));

    gallery = (Gallery) findViewById(R.id.galImage);

    gallery.setAdapter(new ImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int count,long arg3) {
            iSwitcher.setImageResource(array[count]);

        }

    });




}
</code></pre>
