Created
March 19, 2018 08:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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