Linear Clickable Layout

1

How do I make my layout clickable?

For example, I divide the screen into 2 layouts, 1 green with 50% of the screen and the other red with the other 50%. How do you make them clickable?

    
asked by anonymous 20.11.2015 / 18:34

2 answers

5

Set the XML of your layouts to the tag:

android:clickable=“true”

After that, you only have to treat the click as you treat the click in any other view, like a button, for example.

    
20.11.2015 / 18:44
2
LinearLayout meuComponente = (LinearLayout) findViewById (R.id.meu_componente);
meuComponente.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(this, "hello", Toast.LENGTH_LONG).show();
            //Insira qualquer comportamento aqui. (:
    }
});

Do not forget to set the attribute of your LinearLayout :

android:clickable="true"

If you want elements within LinearLayout not to be clickable, use: android:clickable="false" for all elements.

    
23.11.2015 / 03:31