Skip to content

Instantly share code, notes, and snippets.

@jtryan
Last active July 24, 2016 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtryan/6f21dabb0fb256c4f7856953d7d92dff to your computer and use it in GitHub Desktop.
Save jtryan/6f21dabb0fb256c4f7856953d7d92dff to your computer and use it in GitHub Desktop.
Android OnClick for layout

#Add onClick for layout

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rv_layout);
layout.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
       // Do Actions
    }
});

###Cycle through children

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rv_layout);
layout.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
      ViewGroup viewGroup = (ViewGroup) view;
      for (int i = 0; i < viewGroup .getChildCount(); i++) {

       View viewChild = viewGroup .getChildAt(i);
       // Do somthing with Child

          }
    }
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment