Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

permissions - Tab Widget Issue when use android:configChanges="orientation|keyboardHidden" in Grid View but working for other Tab

I am stuck with my issue.Thing is that its a custom Tab Widget.In that have multiple tab like Home - News - Abc - PQR .

The Activity should be for both orientation like portrait and landscape. so for that each tab have two xml for portrait which is store at layout-port/file.xml and landscape which store at layout-land/file.xml

For manage orientation portrait to landscape i have added android:configChanges="orientation|keyboardHidden" rule tag in each activity.

  • TAB_SAMPLE.java Tab file.
  • TAB_GROUP_ACTIVITY each Tab Group activity File
  • file.java Task file

After all this stuff i get issue here :

If i addandroid:configChanges="orientation|keyboardHidden"rule tag in tab_sample activity then its working perfect. like manage different view. port to land and land to port but its not working in Home.java.

Now if i remove android:configChanges="orientation|keyboardHidden" rule tag in tab_sample activity then its working for Home activity not for News.java

Mean when i change the orientation its keeping same xml form port not use from layout-land.in the sense its call OnCreate() again.

So as i found may be issue is in Tab Widget.

Update

Now after tracing my code i get that main issue is in grid view activity because its only activity which is not working.

Issue is between Tab host v/s Grid View. I don't know why its not taking layout-land xml file. i found this as same issue but no replay on that question also

see in Detail manifestfile.xml I want to maintain both portrait and landscape in all activity.

Both XML File

Please help me how to solve this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...