tags:

views:

15

answers:

1

Hi i want to display the number of images according to one number.That means if number is 1 i want to displat only one imageview in grid,if number is 3 i want to display the 3 images in grid .But i take only one image that means depending on the number that image will be displayed th

A: 

I think you mean like this:

// images zero.png, one.png and so on is located in the res/drawable folder 
private Integer getImg(Integer val)
    {
        if (val == 0)
            return R.drawable.zero;
        else if (val == 1)
            return R.drawable.one;
        else if (val == 2)
            return R.drawable.two;
        else if (val == 3)
            return R.drawable.three;
        else if (val == 4)
            return R.drawable.four;
        else if (val == 5)
            return R.drawable.five;
        else if (val == 6)
            return R.drawable.six;
        else if (val == 7)
            return R.drawable.seven;
        else if (val == 8)
            return R.drawable.eight;
        else 
            return R.drawable.nine;
    }

... and call this method using this statement:

// Number "3" should be replaced with a variable name
img1.setImageResource(getImg(3));

img1 is the ImageView variable.

BennySkogberg
But actually i want to display if number is 3 ,then 3 times that image will be displayed
sairam