I call new TableRow() because parentView is parent TableRow . If your parent view is LinearLayout , replace it with new LinearLayout.LayoutParams .
textView.setLayoutParams( new TableRow.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
source share