In my code i m trying to find the height the textview occupies..
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = new TextView(this);
ViewTreeObserver vto = t.getViewTreeObserver();
vto.addOnGlobalLayoutListener(this);
t.setText("This is to test the text\n Some Text \n Another ..");
t.append("\nafter something");
Toast.makeText(this, " The value at num = "+num,Toast.LENGTH_SHORT).show();
setContentView(t);
}
public void onGlobalLayout() {
// TODO Auto-generated method stub
num=t.getHeight();
Toast.makeText(this, "Hellooo !! height is "+num, Toast.LENGTH_SHORT).show();
}
The value of num in onCreate() is always zero but atlast in the onGlobalLayout() , the correct height is getting stored in num but i cant use it because it is the end of the application ..
Is there any possibility of getting the text length in the middle of the application ?
Forgive, if there are any mistakes in the above problem..
Thanks,
Siva Kuamr
That’s not the end of the application, that’s when Android has finished layout. If you need that to be the “middle” of the application, call in
onGlobalLayout()some method that will use the height value. See Event-driven programming.