I am trying to add some objects to a ScrollView but I am getting a NULL POINTER EXCEPTION because I believe that the object has not been created yet from the method call setContentView which I assume launches some new threads to finish the task. How can I know when inflation is done from the Activities point of view. I do not want to extend ScrollView and override it’s onFinishInflation method though.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScrollView v = (ScrollView)super.findViewById(R.id.scrollview);
for(int i=0;i<20;i++)
{
TextView tv = new TextView(this);
tv.setText("Blah");
v.addView(tv);
}
}
As soon as the call to setContentView exits, your views are created. There is another bug in your code that is causing the problem you are seeing. Perhaps your id or layout is wrong.