1

I want to check if one matrix with R.drawable items contains the current ImageView.

A small part of my code is:

        Integer[] redColor = { R.drawable.red_circle_, R.drawable.red_cross_};

        Random random = new Random();
        int randomItem = random.nextInt( redColor.length );

        item1ImageView.setImageResource( redColor[ randomItem1 ] );

        if ( ( Arrays.asList( redColor ).contains( item1ImageView.getId() )
        {
            //do something
        }
Panagiotis
  • 511
  • 8
  • 26

2 Answers2

0

If you want to identify the imageviews by their drawable resource ids, you could make use of the view's tag.

After calling the setImageResource for a given view, set that view tag with the same resource id (imageview.setTag(R.drawable.asset_id)).

You can get that id back by casting the call ((int) imageview.getTag()).

0

The easy way is:

    Integer[] redColor = { R.drawable.red_circle_, R.drawable.red_cross_};

    Drawable.ConstantState[] redColorConstantState = new Drawable.ConstantState[ 3 ];

    for ( int counter = 0; counter < redColor.length; counter++ )
    {
        redColorConstantState[ counter ] = getResources().getDrawable( redColor[ counter ] ).getConstantState();
    }

    Random random = new Random();
    int randomItem = random.nextInt( redColor.length );

    item1ImageView.setImageResource( redColor[ randomItem1 ] );

    if ( ( Arrays.asList( redColorConstantState ).contains( item1ImageView.getDrawable().getConstantState() )
    {
        //do something
    }
Panagiotis
  • 511
  • 8
  • 26