1

How to change textview maxLines in orientation mode change? For example, in portrait mode 4 maxlines, but in landscape 2 maxlines. i tried with below code, but not success, only in portrait mode its show 4 lines, but in landscape not show 2 lines:

MainActivity

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          maxlines();
             case...
             default:
                        break;
                }

........................

private void maxlines(){
        if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
            arabicfont.setMaxLines(4);
        }else{
            if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
                arabicfont.setMaxLines(2);
            }
        }
    }

Manifest

<activity
            android:name=".MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
6
  • 2
    Override onConfigurationChanged in tour activity and to put maxlines on it
    – crgarridos
    Jul 23, 2018 at 23:39
  • Once again question. How to do since 1st launch app, its recognize screen as a portrait? because, when 1st time launching app and i click on listview item, itsnot showing 4 maxlines (its fill all layout), but after landscape and then going back to portrait its showing 4 lines Jul 23, 2018 at 23:57
  • @alizulfuqar call the maxlines() function from the onResume() method. Jul 24, 2018 at 0:03
  • I want add to onCreate rather than onResume. Because resume is resume, i want launch app Jul 24, 2018 at 1:39
  • @alizulfuqar Please refer to the lifecycle chart that I added in the answer section. onResume will also be launched when onCreate is launched. Jul 30, 2018 at 1:19

1 Answer 1

0

There are two ways to solve this method:

1) Overriding OnConfigurationChanged method: This method is called when the orientation of the device is changed.

2) Overriding OnResume method by calling the maxlines() function from that method: This method is called throughout the activity lifecycle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.