1

Disclaimer: I have already tried following similar threads (namely How can I use OnClickListener in parent View and onTouchEvent in Child View? and How can i get both OnClick and OnTouch Listeners), yet my code still fails to work.
I have a (parent) activity which contains a (child) view. Activity has all the network code, while view contains a bitmap displaying game state. View executes the game moves and draws them, while activity sends and receives the moves.
As such, I need to listen for player's actions on the bitmap, handle them there and immediately after it is handled in the view, I need to send the made move to the server. So the best way I've found to handle all that so far is by using onClickListener along with onTouchListener. But I've spent 4 hours and can't get this to work, so any help would be appreciated.
My parent onClick:

gameView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                //gameView.performClick();
                sendMove(theGame.getLastMove());
            }
        });

My child view:

@Override
    public boolean onTouchEvent(MotionEvent event)
    {
        if(canIMove) {
            float x = event.getX();
            float y = event.getY();
            int recWidth = this.getWidth() / 7;
            int currentWidth = 0;
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    if (x > currentWidth && x < currentWidth + recWidth)
                    {
                        //Bitmap touched
                        theGame.Move();
                        ReloadGameBoard();
                    }
                return true;
            }
        }
        return false;
    }

It matters not whether I try to performClick() in onClick or in onTouch, it doesn't also matter whether I return true or false in onTouch, it doesn't matter whether I put it in ACTION_DOWN nor ACTION_UP, the result is always the same: child View onTouch gets executed and parent onClick does not. And please, if you decide to downvote this, at least tell me why.

Community
  • 1
  • 1
Sazu
  • 11
  • 5

0 Answers0