Reputation: 3890
I know how to create a custom dialog with an predefined XML.
I would like to create a dialog with a LinearLayout and buttons dynamically.
I tried the code below, but its seems my buttons are overlapping. How do I prevent this?
public void createMenu(MenuItem item){
Dialog menuDiag = new Dialog(Home.this);
menuDiag.setTitle("Browse");
LinearLayout linearLayout = new LinearLayout(menuDiag.getContext());
LinearLayout.LayoutParams params;
Button button;
categoryList = parse.getPlayList();
for(int i=0;i<categoryList.size();i++){
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
button = new Button(menuDiag.getContext());
button.setText(categoryList.get(i).getTitle());
button.setBackgroundResource(iconCheck(categoryList.get(i).getTitle()));
button.setLayoutParams(params);
menuDiag.addContentView(button, params);
}
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
menuDiag.addContentView(linearLayout, params);
menuDiag.show();
}
Upvotes: 0
Views: 807
Reputation: 8604
Try setting orientation of your LinearLayout
to Vertical, this way it will automatically be placed below the first View
If you are using LinearLayout
then use
yourLayout.setOrientation(LinearLayout.VERTICAL);
to set the orientation
Upvotes: 1