Associate two image

Asked

Viewed 47 times

2

I wanted to create a app that clicking on an image changed your image and was waiting to click on another image. If the two images were equal (with the same value) activates a button that gave the possibility to pass to another Layout.

I only have the code to change the image.

botao.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {         
    if( ????????? ) 
       botao.setBackgroundResource(R.drawable.preto);                
    else
       botao.setBackgroundResource(R.drawable.verde);

}
  • It is not clear what you want. However, if you want to know is if two images (drawables) are equal see this reply

  • I want to associate two images (like those games that we have to click to discover the images and are only shown when they are iguas)

  • 2

    You want to make a memory game, right?

  • Yes, that was my idea

  • this.. is a memory game... In fact the image is just "the shell" of the problem. this has to be done with programming logic. You can use an arraylist with twenty members, 10 of them being repeated, and shuffle them. then just fill a "gridview" with the arraylist and when you click just check if they are equal.

  • Where can I read more how to make an arraylist? ..

Show 1 more comment

1 answer

0


Algorithm

  1. Create a matrix
  2. Associate each pair (row and column) to an image
  3. At each image click - Check if it is click 1, if changing the image - If it is click 2, reset the click counter and check if the images are equal. If they are equal, Keep the images turned. - Check if images are still being flipped/clicked.

The algorithm is this. Remember to let the image be displayed for 3 seconds if the 2 images are turned nay be equal.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.