Question

I wan't to develop game named "Balda".

I have a 2d grid of imageviews (or buttons, maybe). User should be able move his finger on the grid, and app should know wich images in grid was touched in this move.So, in the picture below is what I'm trying to achieve. A - is start point where user pressed on screen. B is end point where finger leaves the screen. And I need to know what images were touched (There are blue in the picture).

I know that I can do something like this. But I think that this is a wrong solution, because It contradicts the principle of giving functionality by responsibilitys. I think that it is responsibility of the imageView to know when finger enters its borders and when it is leaving its borders. I thought, that this would be in android API. And it has MotionEvent like EVENT_HOVER_ENTER and EVENT_HOVER_LEAVE but it's not working with finger. After finger is pressed on some View it will recieve all other MotionEvents, if I get it right.

I think that this is wrong. What can I do to get this functionality? Maybe I could create some custom listeners and custom Views, that supports them?

enter image description here

Was it helpful?

Solution

I think your requirement is slightly similar to custom gridview.

You can try below steps-

1)Create Custom view

2)Attach TouchListener to it.

3)Divide this view into 4*3 matrix.

4)Map your images to this 4*3 matrix

5)Write a function which gives the cell number respective toTouched Co-ordinates

6)After getting cell number;get the mapped image for that cell number

7)Put this image in arraylist

8)When user lifts his finger you will get arraylist of touched images(do whatever you want with it).

9)Remember to put this custom view in your activity

Tell me,if you have any doubt or concern

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top