Search code examples
androidimageviewontouch

showing and hiding ImageView


I have a project based on this tutorial in which the user rotates a wheel and a value of a number int days changes according to the current position of the wheel , now i want to make another image ImageView circle show or hide according to the value of this number, but it throws NullPointerException

this is my onTouch event and sorry for my bad english

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction()) {

        case MotionEvent.ACTION_DOWN:
            // reset the touched quadrants
            for (int i = 0; i < quadrantTouched.length; i++) {
                quadrantTouched[i] = false;
            }
            allowRotating = false;
            startAngle = getAngle(event.getX(), event.getY());
            break;

        case MotionEvent.ACTION_MOVE:
            double currentAngle = getAngle(event.getX(), event.getY());
            rotateDialer((float) (startAngle - currentAngle));
            startAngle = currentAngle;
            days = ((int) currentAngle / 12) + 1;
            String test = Integer.toString(days);
            tvnumber.setText(test);

            switch (days) {
                case 1:
                    circle.setVisibility(View.INVISIBLE);
                    break;
                case 3:
                    circle.setVisibility(View.VISIBLE);
                    break;
            }
            break;

        case MotionEvent.ACTION_UP:
            allowRotating = false;
            break;
    }
}

my logcat enter image description here


Solution

  • You need to initialize the circle view, most likely with the findViewById() method