1

Hi I was want to add 2 different text views to my linear layout but somehow when i try to add both of them only the first one appears why is this the case? Here is my code :

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    // create the text view for the main string to
    // be displayed
    TextView displayMainText = new TextView(this);
    displayMainText.setTextSize(15);
    displayMainText.setText(mainString);
    displayMainText.setLayoutParams(layoutParams);
    displayMainText.setPadding(0, 20, 0, 0);

    // Create the text view for the optional string to
    // be displayed
    TextView displayOppText = new TextView(this);
    displayOppText.setTextSize(15);
    displayOppText.setText(optionalString);
    displayOppText.setLayoutParams(layoutParams);
    displayOppText.setPadding(0, 20, 0, 0);

    // add text views to the layout
    LinearLayout studyTLayout = (LinearLayout) findViewById(R.id.study_time_layout);
    studyTLayout.addView(displayMainText);
    studyTLayout.addView(displayOppText);
    setContentView(studyTLayout);

With my code it only adds the first text view correctly

1 Answer 1

5

It seems like you didn't set the orientation of the LinearLayout to Vertical.

studyTLayout.setOrientation(LinearLayout.VERTICAL);
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.