I have read probably all posts and documentation but I still can\'t solve this issue.
I want to use addView()
method to add view to the existing (running) l
You forgot to specify the LayoutParameters
for the newly added view.
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
TextView text=new TextView(this);
text.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text.setText("test");
layout.addView(text);
EDIT
The GridView
with an id of @+id/gridview
is defined with a layout height of fill_parent
, leaving you with no space to add a new view. Changing its height to wrap_content
may solve your problem.
Adding my comment to this post to help others easily verify the solution.