1

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;

}

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.