Home How to check whether the user has tapped on a specific part of the screen?
Reply: 0

How to check whether the user has tapped on a specific part of the screen?

user1360
1#
user1360 Published in May 27, 2018, 3:32 am

Hi I'm new to android studio and I have an app that draws some shapes. Currently when I tap the screen once the app deletes the last shape drawn.

However, I need it to delete the shapes only when the user clicks on the top left 1/16 of the canvas followed by the bottom right 1/16 of the canvas?

This is what I tried.Is there something wrong with my getWidth and getHeight?

This is my onViewCreated

 public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getWidth=view.getWidth();
    getHeight=view.getHeight();

OnsingleTap confirmed method

 public boolean onSingleTapConfirmed(MotionEvent e) {
        Cursor cursor = getLastShape();
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
        }
        int x1 = (int) e.getX();
        int  y1 = (int) e.getY();

        if((x1<1/16*getWidth) &&(y1<1/16 * getHeight)){
            int x2 = (int) e.getX();
            int  y2 = (int) e.getY();
            if((x2>=getWidth-1/16*getWidth) && (y2>=getHeight-1/16*getHeight)) {
                resolver.delete(Shape.CONTENT_URI, "_id=" + cursor.getInt(cursor.getColumnIndex(Shape.ID)), null);
            }

        }

     return true;



}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304215 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO