Handling events

Setting up event listeners is done with a dedicated tweak:

button <~ On.click {
  ...
}

Before we setup our button to show the greeting, we need to wire the greeting textbox to a variable:

// create a slot
var greeting = slot[TextView]
...
// in the layout
w[TextView] <~ wire(greeting) <~ OurTweaks.greeting("Hello!")

Now we can complete our layout:

l[LinearLayout](
  w[Button] <~
    text("Click me") <~
    On.click {
      greeting <~ show
    },
  w[TextView] <~
    wire(greeting) <~
    OurTweaks.greeting("Hello!")
) <~ vertical

But what if we want to adapt our layout to the screen orientation? Read on.