so from debugging and commenting out things i have come to the conclusion that the problem from this program is in the addTextView() method. I have absolutely no idea where the problem is going wrong. My guess is in the layout that i am trying to add to the TextView.
thanks you so much in advance for your help.
public class Books extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.books);
addTextView("Hello World");
}
public void addTextView(String text)
{
ScrollView viewport = (ScrollView)findViewById(R.id.books);
TextView textview= (TextView)new TextView(this);
textview.setText(text);
//textview.setLayoutParams(new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
viewport.addView(textview, new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
public void addButton(String text)
{
ScrollView scrollview = (ScrollView)findViewById(R.id.books);
Button btnTag = (Button)new Button(Books.this);
btnTag.setLayoutParams(new ScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btnTag.setText(text);
scrollview.addView(btnTag);
}
}
ScrollViews can only have one child, typically a LinearLayout. When you call
scrollview.addView(blah blah)you’re adding more children to the ScrollView which is not allowed.See here for documentation about ScrollView.
—
On a side note, when posting questions on StackOverflow about errors you encounter, please state:
It’ll help everyone, including people in future who stumble upon this question.