trying to make this code less messy in android, can anyone help?

Posted by clayton33 on Stack Overflow See other posts from Stack Overflow or by clayton33
Published on 2010-12-28T04:37:27Z Indexed on 2010/12/28 4:54 UTC
Read the original article Hit count: 411

Filed under:

i know that there must be a simpler way of doing this, i just don't understand how java works well enough, and i am struggling. could someone perhaps point me in the right direction?

ImageButton image = (ImageButton) findViewById(R.id.card1);
    ImageButton image2 = (ImageButton) findViewById(R.id.card2);
    ImageButton image3 = (ImageButton) findViewById(R.id.card3);
    ImageButton image4 = (ImageButton) findViewById(R.id.card4);
    ImageButton image5 = (ImageButton) findViewById(R.id.card5);
    ImageButton image6 = (ImageButton) findViewById(R.id.card6);
    ImageButton image7 = (ImageButton) findViewById(R.id.card7);
    ImageButton image8 = (ImageButton) findViewById(R.id.card8);
    ImageButton image9 = (ImageButton) findViewById(R.id.card9);
    ImageButton image10 = (ImageButton) findViewById(R.id.card10);
    ImageButton image11 = (ImageButton) findViewById(R.id.card11);
    ImageButton image12 = (ImageButton) findViewById(R.id.card12);
    ImageButton image13 = (ImageButton) findViewById(R.id.card13);
    ImageButton image14 = (ImageButton) findViewById(R.id.card14);
    ImageButton image15 = (ImageButton) findViewById(R.id.card15);
    //image.setImageResource(R.drawable.test2);
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled = Bitmap.createScaledBitmap(bMap, buttonSize, buttonSize, true);
    Bitmap bMap2 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled2 = Bitmap.createScaledBitmap(bMap2, buttonSize, buttonSize, true);
    Bitmap bMap3 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled3 = Bitmap.createScaledBitmap(bMap3, buttonSize, buttonSize, true);
    Bitmap bMap4 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled4 = Bitmap.createScaledBitmap(bMap4, buttonSize, buttonSize, true);
    Bitmap bMap5 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled5 = Bitmap.createScaledBitmap(bMap5, buttonSize, buttonSize, true);
    Bitmap bMap6 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled6 = Bitmap.createScaledBitmap(bMap6, buttonSize, buttonSize, true);
    Bitmap bMap7 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled7 = Bitmap.createScaledBitmap(bMap7, buttonSize, buttonSize, true);
    Bitmap bMap8 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled8 = Bitmap.createScaledBitmap(bMap8, buttonSize, buttonSize, true);
    Bitmap bMap9 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled9 = Bitmap.createScaledBitmap(bMap9, buttonSize, buttonSize, true);
    Bitmap bMap10 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled10 = Bitmap.createScaledBitmap(bMap10, buttonSize, buttonSize, true);
    Bitmap bMap11 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled11 = Bitmap.createScaledBitmap(bMap11, buttonSize, buttonSize, true);
    Bitmap bMap12 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled12 = Bitmap.createScaledBitmap(bMap12, buttonSize, buttonSize, true);
    Bitmap bMap13 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled13 = Bitmap.createScaledBitmap(bMap13, buttonSize, buttonSize, true);
    Bitmap bMap14 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled14 = Bitmap.createScaledBitmap(bMap14, buttonSize, buttonSize, true);
    Bitmap bMap15 = BitmapFactory.decodeResource(getResources(), R.drawable.vraag);
    Bitmap bMapScaled15 = Bitmap.createScaledBitmap(bMap15, buttonSize, buttonSize, true);

    image.setImageBitmap(bMapScaled);
    image2.setImageBitmap(bMapScaled2);
    image3.setImageBitmap(bMapScaled3);
    image4.setImageBitmap(bMapScaled4);
    image5.setImageBitmap(bMapScaled5);
    image6.setImageBitmap(bMapScaled6);
    image7.setImageBitmap(bMapScaled7);
    image8.setImageBitmap(bMapScaled8);
    image9.setImageBitmap(bMapScaled9);
    image10.setImageBitmap(bMapScaled10);
    image11.setImageBitmap(bMapScaled11);
    image12.setImageBitmap(bMapScaled12);
    image13.setImageBitmap(bMapScaled13);
    image14.setImageBitmap(bMapScaled14);
    image15.setImageBitmap(bMapScaled15);

© Stack Overflow or respective owner

Related posts about android