Include all relative layout in a button

My application has a built-in page consisting of some text and image elements in a relative layout. I would like to be able to click on any part of the screen and move on to the next step. Can I use the entire relative layout as a button? If so, how would you do it?

+3
source share
3 answers

You can grab the root view as follows and add a click listener to it:

findViewById(android.R.id.content).setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
         //make your call to startActivity();
     }       
});

This requires less maintenance than getting a specific layout.

+1
source

android:clickable="true" XML RelativeLayout OnClickListener, .

, (, -, ?), onTouchEvent ( MotionEvent) , , .

+2

Add the XML android:onClick="myFunction"to the RelativeLayoutfile and do the following function in the corresponding file Activity:

public void myFunction(View view)
{
   ...
}

I think you will have to add android:onClick="myFunction"for all the nested XML tags that are nested inside the main one RelativeLayout.

0
source

All Articles