Darryl van Kampen
Darryl van Kampen

Reputation: 23

Remove 'tile' when clicked on

I'm working on a small project where you need to guess the picture behind the tiles. Currently everything is working, but I have no idea how I can check if someone clicked a tile.

I know I can do it with a button, but I want to be able to remove a tile when someone actually presses that tile. Is there a way to check if someone pressed somewhere on the screen or something?

Upvotes: 1

Views: 94

Answers (1)

IAmGroot
IAmGroot

Reputation: 13855

You need to make your tile clickable, and then add a method on click event.

Add the following to your tiles in xml.

        android:clickable="true"
        android:onClick="TileClicked"

Then create a method in your activity

public void TileClicked(View v)
{

     int clickedID = v.getId();

     // Do something to the clicked tile .. e.g.
     v.setVisiblity(View.INVISIBLE);

     // or filter specific tiles
     if(clickedID = R.id.myTile1)
     {
         // do something when tile 1 clicked
     }
}

Alternatively, you can add the onclick listener in code and call the method there.

Upvotes: 1

Related Questions