Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The XML layout sample for android on readme is right? #85

Open
fpbitencourt opened this issue Oct 13, 2016 · 2 comments
Open

The XML layout sample for android on readme is right? #85

fpbitencourt opened this issue Oct 13, 2016 · 2 comments

Comments

@fpbitencourt
Copy link

First I translate the kotlin code on readme sample

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gif_list);
        bindingViews();
    }

    private void bindingViews() {
        xml(R.layout.activity_gif_list, () -> {
            withId(R.id.loading, () -> {
                visibility(progressVisibility);
            });
        });
    }

and how I make it works

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gif_list);
        bindingViews();
    }

    private void bindingViews() {
        Anvil.mount(findViewById(R.id.activity_gif_list), () -> {
            withId(R.id.loading, () -> {
                visibility(progressVisibility);
            });
        });
    }

I can fix it on readme if you approve...

@mitchryanjusay
Copy link

So what's happening here is that your inflatimg the xml on setcontentview and then mounting it onto anvil for the bindings. Have you tried calling anvil.render()? Cause it currently has a bug with xml views however thats with building the view through anvil renderable.

@zserge
Copy link
Collaborator

zserge commented Nov 5, 2016

@fpbitencourt Sorry, which example do you refer to?

xml() works only inside Renderables (e.g. RenderableViews or lambdas). In the first snippet you first inflate the XML layout into the activity (or fragment?), so there is no need to use xml() anymore since it does the same.

I would write it as:

protected void onCreate(Bundle b) {
  super.onCreate(b);
  setContentView(new MyView(this)); // I like to keep activities small and dumb
}

class MyView extends RenderableView {
  ...
  public void view() {
    xml(R.layout.activity_git_list, () -> { // this will inflate the layout into the MyView view group
      withId(R.id.loading, () -> { // this will update the "loading" widget inside the given XML layout
       visibility(progressVisibility);
      });
    });
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants