0

Can anyone tell me please how can I make the whole blank screen clickable on the android ? Means wherever I can click on it and then the place where i click there one particular image has to appear where i can then make the notes. I am trying to first find the coordinates of that area and then putting the image. But i am not able to find the code for doing that. Means after finding the coordinates what can be done?

Or if there is some other way then also please help with that!!

For finding coordinates:

public class MainActivity extends Activity implements OnTouchListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView xCoord = (TextView) findViewById(R.id.button1);
    final TextView yCoord = (TextView) findViewById(R.id.button2);

    final View touchView = findViewById(R.id.button3);
    touchView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            final int action = event.getAction();
            switch (action & MotionEvent.ACTION_MASK) {

                case MotionEvent.ACTION_DOWN: {
                    xCoord.setText(String.valueOf((int) event.getX()));
                    yCoord.setText(String.valueOf((int) event.getY()));
                    break;
                }

                case MotionEvent.ACTION_MOVE:{
                    xCoord.setText(String.valueOf((int) event.getX()));
                    yCoord.setText(String.valueOf((int) event.getY()));
                    break;
                }
            }

            return true;

        }

    });

}
1
  • Have an ImageView ready... make it invisible. When they click - set the coords of the ImageView to where they clicked AND make it visible :)
    – d'alar'cop
    Sep 7, 2013 at 15:12

1 Answer 1

0
  1. Create an ImageView (or have one in your Layout)
  2. Make sure it's invisible on initialisation
  3. When the user clicks use the coordinates to set the location of the ImageView
  4. Make the ImageView visible
  5. Take a sigh of relief.
15
  • Thank you very much for this idea..but i just wanted to know that how can we place an imageview at the calculated coordinates??
    – Gaur
    Sep 10, 2013 at 9:39
  • stackoverflow.com/questions/16782705/android-setx-and-sety-behaving-weird
    – d'alar'cop
    Sep 10, 2013 at 10:05
  • Thank you for your answer. Yes that link was of help and i was able to do it!!:)
    – Gaur
    Sep 13, 2013 at 6:14
  • Excellent! Do you think I could trouble you to tick the answer? All the best :)
    – d'alar'cop
    Sep 13, 2013 at 6:31
  • In this what can i do if i want multiple images on my screen but only after a touchevent. I am able to achieve that for two images. Like one time i touch one image appears, another time i touch, another image appears, like this.
    – Gaur
    Sep 13, 2013 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.