Reputation: 6359
I use Objects (beans) that we'll call Category. These Category objects contain a set of attributes including a list of Category objects.
public class Category {
private List<Category> categoryList;
...
private Strings anAttribute;
}
At compilation, I do not know the depth of the root Category object, meaning : how many Category are in the list of the root Category and how many Category objects are in each one of the list and so go on. I actually get the root Category object by parsing an XML file.
I have an activity, which, to resume, shows a set of buttons. Each button represents a root Category object (each from an XML file). I would like that once I click on one of these buttons, I get a new "window" showing a set of buttons (a button per Category in the List) and each of this button shows recursively a new "window" showing a set of buttons...
How could I do that knowing I'd like to use XML files for the contents I want to display ? I guess the point is not to create an activity per Category (even dynamically).
Thank you for your help.
Upvotes: 2
Views: 79
Reputation: 8702
You could use the following structure:
private LinearLayout myLayout;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.something);
myLayout = (LinearLayout) findViewById(R.id.my_layout);
createBtns( loadFirstCategory() );
}
private void createBtns(Category c)
{
List<Category> c_list = c.getCategoryList();
for (int i=0; i<c_list.size(); i++)
{
Button btn = new Button(this);
btn.setText( c_list.get(i).getName() );
myLayout.addView(btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick()
{
myLayout.removeAll();
createBtns( c_list.get(i) );
}
});
}
}
Upvotes: 3