Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fire an event when someone clicks anywhere on the screen in an android app?

Tags:

android

events

how can I catch the event when click occurs somewhere on the app screen? It doesn't matter if there is a button or something else. I just need to apply an onClick() event listener on the whole application screen.
How to do this?

like image 598
gurehbgui Avatar asked Apr 12 '12 15:04

gurehbgui


1 Answers

setonclicklistner for main layout of your layout file....

Like....main.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/mainlayout">  <!- Your other view-> </Relativelayout> 

and set click listener for mainlayout...

 RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.mainlayout);  rlayout.setOnClickListener(new OnClickListener() {      @Override     public void onClick(View v) {      }   }); 
like image 66
Samir Mangroliya Avatar answered Sep 23 '22 17:09

Samir Mangroliya