txusballesteros/welcome-coordinator

Click event of a button contained in a WelcomePageLayout

Closed this issue · 4 comments

Let's say I have a button inside a WelcomePageLayout, how should I access its click listener? throughout behaviours or directly on the main activity which holds the coordinator? Is the coordinator layout inflating all WelcomePageLayout thus I can access any view contained on them?

Cheers and thanks!

Never mind, going through the code I saw each page is inflated upon adding, hence any widget in them can be used after invoking the coordinator add() method.

@mradzinski I am trying to achieve the same thing. Can you please tell me how you managed to do it? Get a UI widget from the current page?

A code snippet would be helpful.

Cheers

@younisshah AFAIK, each page is inflated upon adding it (addPage method), so, views contained in them should be accessible the moment your activity containing the welcome coordinator kicks in. I was using Kotlin for the project, so probably any code snippet I can provide will be of no help to you...

I'm writting this by heart, but it should be something like this.

public void onCreate() { // <--- onCreate method of the activity containing the welcome-coordinator viewaccessible
  ...
  WelcomeCoordinator welcomeCoordinator = (WelcomeCoordinator) this.findViewById(R.id.welcome_coordinator);
  welcomeCoordinator.addPage(
      R.layout.welcome_page_1,
      R.layout.welcome_page_2 // <--- This page has a button called btn_test
  );

  Button btnTest = (Button) this.findViewById(R.id.btn_test);
  btnTest.setOnClickListener(...)
}

Bare in mind I haven't used this library in a while, but I guess this should put you on track.

@mradzinski works like a charm 👍

Thanks muchly!