Skip to content

Instantly share code, notes, and snippets.

@zserge
Created February 21, 2017 11:32
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 zserge/0c066cfa7039632da8e2b530dc69f765 to your computer and use it in GitHub Desktop.
Save zserge/0c066cfa7039632da8e2b530dc69f765 to your computer and use it in GitHub Desktop.
Reproducing Anvil issue #83
package trikita.foo;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;
import trikita.anvil.RenderableView;
import static trikita.anvil.DSL.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new OuterView(this));
}
public static class OuterView extends RenderableView {
private int mode = 0;
public OuterView(Context c) { super(c); }
public void view() {
linearLayout(() -> {
orientation(LinearLayout.VERTICAL);
button(() -> {
text("change mode ("+mode+")");
onClick(v -> mode++);
});
v(InnerView.class, () -> {});
if (mode % 2 == 0) {
v(InnerView.class, () -> {
});
}
v(InnerView.class, () -> {});
});
}
}
public static class InnerView extends RenderableView {
public InnerView(Context context) { super(context); }
public void view() {
xml(R.layout.activity_main, () -> {
withId(R.id.button, () -> {
text("Hello, button");
});
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment