1

Here is my code. In the resulting screen it shows only the first TextView. Not the second one. Im kind of new to Android and please give a help.

public class Details extends Activity {
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        TextView label = new TextView(this);
        label.setText("Moves");
        label.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        label.setTextSize(20);        

        TextView label2 = new TextView(this);
        label2.setText("Time");
        label2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        label2.setTextSize(20);       

        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);                           

        ll.addView(label);
        ll.addView(label2);

        setContentView(ll);
    }               
}

1 Answer 1

2

You forgot to tell the LinearLayout how to stack its children (Orientation). Without that it won't stack them at all and will ONLY display the first item (I believe).

http://developer.android.com/reference/android/widget/LinearLayout.html#setOrientation(int)

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

4 Comments

wait.. why are both your textfire fill_parent.. ? YOU DO KNOW that the entire screen will be consumed by one of those.. even if you stack them.. try this.. set the width to fill_parent and the height to wrap_content on BOTH textviews, leave the LinearLayout as Fill_Parent on both height/width
The way you had it before was both textviews occupied the entire screen.. and TextView1 was ontop of TextView2, which of course won't stack because they both as large as the screen (Fill_Parent)
Thank you. It worked. I changed Layout to Fill_Parent and Text_Views to Wrap Content.
Keep practicing your view and layout properties, try to know them well.. know what each of them mean.. and it helps debug these kinds of problems.

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.