Change Text on Landscape mode with Java Code and not XML (Android)
- by Chowza
I wrote my layout entirely in java code because it was just more convenient. (I had a lot of textViews and using for statements were more convenient).
However, my TextViews require the day of the week and in portrait mode, I would like to cut the day of the week to a short form. For example, I want "Sunday" to show "Sun" for portrait mode, but "Sunday" for landscape mode.
I understand how to do this in XML files, but how do I do it in code?
I.e. sample code:
LinearLayout parent = new LinearLayout(getApplicationContext());
parent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
TextView example = new TextView;
example.setLayoutParams(mparams);
example.setText("Sunday"); //<--make this "Sun" when in portrait but "Sunday" in landscape
parent.addView(example);