A button with different options to download different images
<p>People! I'm new at Java and Android developement. I'm trying to write a simple code so i can push on a button and it views a list with different options. Each option downloads a image and the image is coming from a ftp server. The problem is the download image don't work and it's a separate button. That means i have two buttons, one to view the option list and one to download. The option doesnt do much except shows a list. I want to click on the option button and choose for example "DICE" and it downloads a image from ftp server.</p>

<p>Here is my code:</p>

<pre><code>public class HelloWorldActivity extends Activity 
{
    CharSequence[] items = { "Massive", "Dice", "EA"};
    boolean[] itemsChecked = new boolean [items.length];

    ImageView imView;
    String imageUrl = "http://chuuck.blogg.se/images/2009/adriana-lima6_43297496.jpg";
    Random r = new Random();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button bt3 = (Button)findViewById(R.id.get_imagebt);
        bt3.setOnClickListener(getImgListener);

        imView = (ImageView)findViewById(R.id.imView);


        Button btn = (Button) findViewById(R.id.btn_lista);
        btn.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v)
            {
                showDialog(0);
            }

        });
    }


    View.OnClickListener getImgListener = new View.OnClickListener() 
    {

        @Override
        public void onClick(View view) 
        {
            // TODO Auto-generated method stub
            int i = r.nextInt(4);
            downloadFile(imageUrl+"png"+i+".png");
            Log.i("im url", imageUrl+"png"+i+".png");
        }
    };


    @Override
    protected Dialog onCreateDialog(int id)
    {

            switch (id)
            {
                case 0:
                return new AlertDialog.Builder(this)
                        //.setIcon(R.drawable.bbb)
                        .setTitle("Välj klass!")
                        .setPositiveButton("OK", new DialogInterface.OnClickListener()
                        {
                            public void onClick(DialogInterface dialog, int whichButton)
                            {
                                Toast.makeText(getBaseContext(),
                                        "OK clicked!", Toast.LENGTH_SHORT).show();
                            }
                        })

                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener()
                        {
                            public void onClick(DialogInterface dialog, int whichButton)
                            {
                                Toast.makeText(getBaseContext(),
                                        "Cancel clicked!", Toast.LENGTH_SHORT).show();
                            }
                        })

                        // setMultiChoice(items, itemsChecked)
                        .setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() 
                        {
                                    // (boolean isChecked)
                                    @Override
                                    public void onClick(DialogInterface dialog, int whichButton) 
                                    {
                                        //Toast.makeText(getBaseContext(),
                                                //items[which] + (isChecked ? " checked!": " unchecked!"), Toast.LENGTH_SHORT).show();
                                    }

                        }

            )
            .create();

        }
        return null;

    }

    Bitmap  bmImg;
    void downloadFile(String fileUrl)
    {
        URL myFileUrl = null;
        try
        {
            myFileUrl = new URL(fileUrl);
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        try
        {
            HttpURLConnection conn = (HttpURLConnection)myFileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();

            bmImg = BitmapFactory.decodeStream(is);
            imView.setImageBitmap(bmImg);
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }

}
</code></pre>
