日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android fragment addtobackstack,Android Fragment Back Stack的问题

發布時間:2025/3/8 Android 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android fragment addtobackstack,Android Fragment Back Stack的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我對android片段Backstack的工作方式遇到了一個很大的問題,對于提供的任何幫助將不勝感激。

假設您有3個片段

[1] [2] [3]

我希望用戶能夠導航[1] > [2] > [3]但在返回的途中(按返回按鈕)[3] > [1]。

就像我想象的那樣,這可以通過addToBackStack(..)在創建將片段[2]帶入XML定義的片段持有者的事務時不調用來實現。

現實情況似乎是,如果我不想[2]在用戶按下“后退”按鈕時再次出現[3],則我不能調用addToBackStack顯示片段的事務[3]。這似乎完全違反直覺(也許來自iOS世界)。

無論如何,如果我這樣做,當我離開[1] > [2]并按回去時,我會按[1]預期到達。

如果我走了[1] > [2] > [3]然后按回去,我跳回了[1](按預期)。現在,當我嘗試[2]從再次跳到時,就會發生奇怪的行為[1]。首先在[3]顯示之前簡要顯示[2]。如果此時我按回,[3]將顯示,如果我再次按回,則該應用程序退出。

誰能幫我了解這里的事嗎?

這是我的主要活動的布局xml文件:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/headerFragment"

android:layout_width="match_parent"

android:layout_height="wrap_content"

class="com.fragment_test.FragmentControls" >

android:id="@+id/detailFragment"

android:layout_width="match_parent"

android:layout_height="fill_parent"

/>

更新 這是我用來通過導航繼承構建的代碼

Fragment frag;

FragmentTransaction transaction;

//Create The first fragment [1], add it to the view, BUT Dont add the transaction to the backstack

frag = new Fragment1();

transaction = getSupportFragmentManager().beginTransaction();

transaction.replace(R.id.detailFragment, frag);

transaction.commit();

//Create the second [2] fragment, add it to the view and add the transaction that replaces the first fragment to the backstack

frag = new Fragment2();

transaction = getSupportFragmentManager().beginTransaction();

transaction.replace(R.id.detailFragment, frag);

transaction.addToBackStack(null);

transaction.commit();

總結

以上是生活随笔為你收集整理的android fragment addtobackstack,Android Fragment Back Stack的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。