When creating an imageView and Textview via code how to remove via code?

Asked

Viewed 90 times

0

Good create that way

 TextView textView = new TextView(this);
textView.setText("Alguma coisa");
LinearLayout linear = (LinearLayout)findViewById(R.id.layoutVertical);
linear.addView(textView);

and to remove I did so

linear.removeView(textView);

But did not remove it will be that another way to remove?

  • Don’t forget to use in removeView(textView) the same instance of textView that used in addView(textView)

  • Wouldn’t it be easier to change the visibility to Gone? textView.setVisibility(Visible.GONE);

  • @ramaral you are referring to linear?

  • Both of you, both of you linear as to the textview

1 answer

1

In this case use the setVisibility method of the Textview class, passing as parameter View.GONE, so the element will not be visible, nor will it occupy space in Linearlayout.

textView.setVisibility(View.GONE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.