Change Text on Landscape mode with Java Code and not XML (Android)
Posted
by
Chowza
on Stack Overflow
See other posts from Stack Overflow
or by Chowza
Published on 2012-09-15T21:07:03Z
Indexed on
2012/09/15
21:38 UTC
Read the original article
Hit count: 151
android
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);
© Stack Overflow or respective owner