I have found a couple ways to do this, but my issue is that my code has to be a LinearLayout with a horizontal orientation. So what happens is the dynamically created TextViews go off the screen.
The code I have is below:
mProductAttrLayout.setOrientation(LinearLayout.HORIZONTAL);
mProductAttrLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
for (ProductAttribute productAttribute : aProductAttributes) {
String name = productAttribute.getName();
TextView attr = new TextView(getContext());
attr.setText(name);
attr.setPadding(8, 8, 8, 8);
attr.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
attr.setTextColor(getResources().getColor(R.color.black));
mProductAttrLayout.addView(attr);
for (int i = 0; i < productAttribute.getValues().size(); i++) {
TextView value = new TextView(getContext());
value.setText(productAttribute.getValues().get(i));
value.setTextColor(getResources().getColor(R.color.black));
value.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
value.setPadding(8, 8, 8, 8);
mProductAttrLayout.addView(value);
}
}
What I currently have is:
| name: value, value, value, val--|
what I need is something like:
name: value, value(unknown number of values)
but I need it to go the the next line in the screen if it's too wide like below:
| name: value, value, value,---|
| value, value, value. ------------|
Hope you can understand what I need?