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"?
Asked
Active
Viewed 2,178 times
3 Answers
2
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
}

amrinder007
- 1,455
- 1
- 12
- 13
1
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.

Community
- 1
- 1

Srikant Sahay
- 885
- 6
- 9
-
on click on screen? how can i reckonize the background? – Yonatan Balas Jun 04 '13 at 12:52
1
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
}
}
}

Daniel Scott
- 1,867
- 3
- 13
- 18