Android:onBackPress片段重新加载

时间:2018-11-07 21:02:31

标签: android android-studio android-layout android-fragments onbackpressed

我有一个导航活动,其中包含10个由WebView组成的片段。

现在,当我从“ A”片段输入/传输到“ B”,然后再onBackPress输入/传输时,它会转换回“ A”,但会重新加载。

我想回到留有“ A”的位置。

1 个答案:

答案 0 :(得分:0)

如果您想正确执行操作,请使用{ "IndustryCode": [{ "attrCodeValue": 25838, "attrTypeText": "DBH Industry Code", "IndustryCode": { "txt": "1063" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 9120, "txt": "Legal Services" }], "DisplaySequence": 1 }, { "attrCodeValue": 700, "attrTypeText": "NAICS", "IndustryCode": { "txt": "541110" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 9120, "txt": "Offices of Lawyers" }], "DisplaySequence": 1 }, { "attrCodeValue": 24664, "attrTypeText": "North American Industry Classification System 2012", "IndustryCode": { "txt": "541110" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 9120, "txt": "Offices of Lawyers" }], "DisplaySequence": 1 }, { "attrCodeValue": 21182, "attrTypeText": "UK SIC 2003", "IndustryCode": { "txt": "74.110" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 9120, "txt": "Legal activities" }], "DisplaySequence": 1 }, { "attrCodeValue": 3599, "attrTypeText": "DBS Industry Code", "IndustryCode": { "txt": "81119901" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 2121, "txt": "GENRL PRACTICE ATTY" }], "DisplaySequence": 1 }, { "attrCodeValue": 399, "attrTypeText": "US Standard Industry Code 1987 - 4 digit", "IndustryCode": { "txt": "8111" }, "IndustryCodeDescription": [{ "attrLanguageCode": 39, "attrIndustryCodeDescriptionLengthCode": 1441, "txt": "Legal services office" }], "DisplaySequence": 1 } ] } ,这里是guide

如果这太复杂了,您可以通过在片段ViewModel期间将数据保存在活动中的某个位置来模仿ViewModel。例如:

onPause()

并添加到您的boolean alreadyLoaded = true; boolean btn1Shown = true; String editText1Text = editText1.getText().toString;

onCreateView()

这可能需要一些接口或公共活动方法,这就是为什么存在ViewModel的原因,因此您不必执行这些操作。