Skip to content

Instantly share code, notes, and snippets.

@curioustechizen
Created March 19, 2018 08:33
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 curioustechizen/9c1b1bf64523941d1864e6e8a22ebd9a to your computer and use it in GitHub Desktop.
Save curioustechizen/9c1b1bf64523941d1864e6e8a22ebd9a to your computer and use it in GitHub Desktop.
Android: Cascade the value of a custom attribute from a parent view to a child view - solution to https://stackoverflow.com/q/15112522/570930
// See https://stackoverflow.com/q/15112522/570930
class CustomLayout extends WhateverLayout {
private float percent;
private CustomView customView;
//View constructors go here
private void init(){
//Inflation goes here if needed
percent = //get value passed in to app:percent using TypedArray
}
@Override public void onFinishInflate(){
customView = findViewById(R.id.customView1);
customView.setPercent(percent);
}
}
class CustomView extends WhateverView {
private float percent;
//View constructors go here
public void setPercent(float percent) {
this.percent = percent;
//update the UI using this newly set percent
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment