Tab Widget Issue when use android:configChanges=“orientation|keyboardHidden” in Grid View but working for other Tab

三世轮回 提交于 2019-11-29 15:24:53
Chintan Khetiya

Oooohhh Finally i got the solution for above issue. It's was very difficult.

For maintain the state of orientation Landscape to portrait and vice-versa we generally adding android:configChanges="keyboardHidden|orientation" property tag under activity.

But here may be issue is Tab_Group_ Activity due to that i am not able to maintain state in GridView. Grid_File.java is Only single java file which was not handling the orientation rest of all other working perfectly.

Now if i remove android:configChanges="keyboardHidden|orientation" from TAB_SAMPLE.java then Its handling only Grid_File.java not others.

mean that was keeping same Layout XML in landscape also where i have two separate XML File.

Here is my solution:

I have add android:configChanges="keyboardHidden|orientation" in TAB_SAMPLE.java as well as implement onConfigurationChanged(Configuration newConfig) and set Number of column of grid. like gridView.setNumColumns(6);

@Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        // gridView.setSelection(index);
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {

            // Log.e("On Config Change", "LANDSCAPE");
            gridView.setNumColumns(6);

        } else
        {

            // Log.e("On Config Change", "PORTRAIT");
            gridView.setNumColumns(4);
        }
    }

Generally we are adding either android:configChanges="keyboardHidden|orientation" tag under activity or implementing onConfigurationChanged(Configuration newConfig) but here i have written both.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!