Question

i have a blank screen on mainactivity. when i tap everywhere on the screen it will do an action. such as opening a new activity or making and event. is it possible to make it on an imageview too? what is the listener that listens to the tapping and how can i get a method such as "OnTap"?

Was it helpful?

Solution

I know little about android but sure this can help:

create an ImageView with height and width set to match_parent

<ImageView

   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:onClick="tap_me"

   />

then in your java code you can do this

public void tap_me(View v){
    //do something
}

OTHER TIPS

View.onClickListener should do the work for you.

Update:

Check out similar problem: How to Set onClicklistener Method of ImageView in Android?

You can only detect clicks within your app. Make the imageview to cover the entire screen. Then click on any point will be picked up by the onClickListener.

You could also do something like this:

    ImageView imageView = (ImageView) findViewById(R.drawable.YourImage);
    imageView.setOnTouchListener(new OnTouchListener) {

       @Override
       public boolean onTouch(View view, MotionEvent me) {
            switch(me.getAction()) {
            case(MotionEvent.ACTION_DOWN):
                //do stuff here
            }
       }

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