Android - onTextChanged() called on when phone orientation is changed

后端 未结 2 1443
梦谈多话
梦谈多话 2021-02-06 02:32

I tried to implement search using EditText. whenever a text is typed in the EditText request is sent with the typed text in onTextChanged()

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 02:43

    You need to override onConfigurationChanged method to get callback whenever orientation is getting changed.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // landscape
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            // portrait
        }
    }
    

    Add below line in manifest

    android:configChanges= "orientation"
    

    Now based on the callback you can do whatever you wanted to do.

提交回复
热议问题