View Operations
General Operations
Most of the view operations are same as the PlaceHolderView's operation. This doc can be found here.
Deprecated Methods
Following methods should not be used as it will produce unexpected results.
expandableView.addView(2, someItemView)
expandableView.addViewBefore(someItemView1, someItemView2)
expandableView.addViewAfter(someItemView1, someItemView2)
Add parent and child view
expandableView.addView
automatically infer if it is parent or child. All views added after a parent view is considered as its child only if it is not a parent itself.
public class ExpandableActivity extends AppCompatActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
expandableView.addView(new HeadingView(getApplicationContext(), "Heading 1")) //parent 1
.addView(new InfoView(getApplicationContext(),
new Info("Title1", "https://example/image1.png"))) //child 1 of parent 1
.addView(new InfoView(getApplicationContext(),
new Info("Title2", "https://example/image2.png"))) //child 2 of parent 1
.addView(new HeadingView(getApplicationContext(), "Heading 2")) //parent 2
.addView(new InfoView(getApplicationContext(),
new Info("Title1", "https://example/image1.png"))) //child 1 of parent 2
.addView(new InfoView(getApplicationContext(),
new Info("Title2", "https://example/image2.png"))) //child 2 of parent 2
.addView(new InfoView(getApplicationContext(),
new Info("Title2", "https://example/image3.png"))) //child 1 of parent 2
...
}
}
Add child view to a parent using the parent's view instance.
expandableView.addChildView(parentView, childView);
Add child view to a parent using the parent's view position.
expandableView.addChildView(2, childView);
Expand Programmatically
A parent can be expanded programmatically by using either its instance or position.
try {
expandableView.expand(parentItemView);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
try {
expandableView.expand(2);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
Collapse Programmatically
A parent can be collapse programmatically by using either its instance or position.
try {
expandableView.collapse(parentItemView);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
try {
expandableView.collapse(2);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
Collapse all the parents.
expandableView.collapseAll();