Reputation: 1705
I am trying to create nested linearlayouts dynamically and setting it to activity layout as
setContentView(createLayout());
in oncreate()
.
But I am getting nothing on the screen but a blank screen. Can someone help in pointing out if I am doing it in wrong way?
private LinearLayout createLayout() {
Log.d(TAG,"calling cretaelayout");
LinearLayout main = new LinearLayout(getApplicationContext());
main.setOrientation(LinearLayout.VERTICAL);
int k =0;
for(int i=0 ;i < MainActivity.height*10;i++) {
LinearLayout row = new LinearLayout(getApplicationContext());
row.setOrientation(LinearLayout.HORIZONTAL);
for(int j=0;j< MainActivity.width*10;j++)
{
Log.d(TAG,"creating layout element");
LinearLayout ll = new LinearLayout(getApplicationContext());
ll.setBackgroundColor(Color.BLACK);
ll.setId( k++);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
ll.setOnClickListener(myhandler);
row.addView(ll);
}
main.addView(row);
}
return main;
}
Upvotes: 1
Views: 1382
Reputation: 93561
There's nothing anywhere that takes space. You have a LL inside an LL inside an LL, with the last LL set to wrap_content. But it has no content inside it, so its size will be 0 in both directions. Elements with no size don't appear. Try making the inner most LLs fixed size, and you should see something.
Upvotes: 2