1

Sorry if this is duplicate post but I am not able to find my answer in similar posts.

So, my requirement is:

I have a linearlayout which have some textViews and editviews. Now I want to add one textview below existing editview at runtime.

The layout is a linear Layout and orientation is vertical.

I am very new to android programming. Any help will be appreciated.

Thanks

1
  • Please add some of the relevant code if possible Commented Feb 5, 2014 at 12:35

3 Answers 3

1

Either you have as many as you need in your xml with visibility:gone and switch them to mTextView.setVisibility(TextView.VISIBLE)or as the one above me who just answered

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

1 Comment

Thanks a lot. This is exactly what I wanted. Other's are also correct but not fulfilling my requirement. Sorry, I can't mark answers as useful because lack of reputation.
0

Use this:

TextView tv1 = new TextView(this);
tv1.setText("FIRST");
tv1.setTextSize(10);
tv1.setGravity(Gravity.CENTER);



LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.setGravity(Gravity.CENTER);
ll.addView(tv1);  

Comments

0
TextView textView = new TextView(mContext);
        textView.setText("Your text");
        mLinearLayout.addView(mTextView);

You can add any View in a LinearLayout using the method: addView

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.