簡體   English   中英

屏幕旋轉后列表從頭開始加載

[英]list starts loading from the beginning after screen rotation

在我的片段中,我有列表。 這個列表是不斷填充的。 但是在屏幕旋轉列表從頭開始加載之后。 垂直方向的數據丟失了,因為水平方向的列表再次開始加載。 所以,我添加了所有我可以在互聯網上閱讀的內容:在我的清單文件中:

android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"

在活動 class 中:

if (savedInstanceState == null) {
            firstFragment = FirstFragment()
            supportFragmentManager
                .beginTransaction()
                .add(R.id.frameLayout, firstFragment!!, "firstFragment")
                .commit()
        } else {
            firstFragment = supportFragmentManager
                .findFragmentByTag("firstFragment") as? FirstFragment
        }

但它沒有幫助。

請設置setRetainInstance(true); 在片段代碼中。

它將阻止重新創建片段實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM