I am an android newbie so forgive me if this question is simple.
Basically I want to port over a java project to Android. By view components in my java application dynamically change depending on the model. I.e the model being display may require n check boxes or n radio boxes depending on the enum TYPE being passed to the view.
In my java display this is achieved by nested loops with the n number each time adding the component to the screen. e.g a simplified version of the code:
if (type == TYPE.CHECKBOXES){
for (int i = 0; i < n ; i++){
add(new JCheckBox());
}}
This is processed for the view each time a next button is pressed (the type changes each time). In android how do i dynamically add and remove components, or do i need to set up a new view for each type?
Many thanks
Sam
In Java you manage your layouts using
JPanelalongwith specific layouts (i.eBorderLayout,FlowLayoutetc.)you add your components to
JPaneland then add yourJPanelto parent or root layout.a little example (as you posted:)
In android you manage your layouts using
ViewGroupwhich has specific subclassed layout design (i.eLinearLayoutmuch like asFlowLayout,RelativeLayoutmay be consideredBorderLayout)You can use these layouts just like a
JPanelJust an addition: The
Componentin Java are calledViewin Android. Most of the control (also called widgets likeButton,EditText,ImageButton,ImageView) in Android are subclass ofView.