I am trying to add text to a text view for which I set the width as Wrap_content. I am trying to get the width of this text. But its mapping is 0 in all cases. How can I get the width of the text field after setting the text in it.
the code looks like this:
LinearLayout ll= new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ll.addView(tv);
tv.setText("Hello 1234567890-0987654321qwertyuio787888888888888888888888888888888888888888888888888");
System.out.println("The width is == "+tv.getWidth());
this.setContentView(ll);
Please offer. Thanks in advance.
source
share