I have 16 imageview, each set to onBtnClick as a listner, inside this method it checks whether the imageview id corresponds to a specific id, I need to change this so it checks the image resource inside the imageview, e.g.
public void onBtnClicked(View v)
{
if( v.getId() == R.id.img1 )
{
Intent guess = new Intent(this, com.Logo_Master.Guesslogo.class);
guess.putExtra("image","img1");
startActivity(guess);
}
}
needs to be something like:
public void onBtnClicked(View v)
{
if( v.getId() == R.drawable.img1 )
{
Intent guess = new Intent(this, com.Logo_Master.Guesslogo.class);
guess.putExtra("image","img1");
startActivity(guess);
}
}
or something similar…..so it checks the image inside the imageview rather than the imageview……
Thank you.
/EDIT/
Random random = new Random( System.currentTimeMillis() );
List<Integer> generated = new ArrayList<Integer>();
for (int i = 0; i < imageViews.length; i++) {
int v = imageViews[i];
int next = random.nextInt( 16 );
if ( !generated.contains( next ) ) {
generated.add( next );
ImageView iv = (ImageView) findViewById( v );
iv.setImageResource( images[next] );
Object tag = (Object) new Integer(getImageName(this, String.valueOf(images[next])));
iv.setTag(tag);
}
else {
i--;
}
}
public static int getImageId(Context context, String imageName) {
return context.getResources().getIdentifier("id/" + imageName + "guess", null, context.getPackageName());
}
public static int getImageName(Context context, String imageName)
{
return context.getResources().getIdentifier("drawable/" + imageName + "guess", null, context.getPackageName());
}
You can use tags to achieve this:
When creating your ImageView (in code or in XML), define a tag:
OR
Then retrieve the tag before you need it by:
Good luck!