亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android 目標片段未出現在導航上

Android 目標片段未出現在導航上

RISEBY 2023-07-28 16:11:19
我正在嘗試使用導航圖在兩個片段之間導航。由于某種原因,當我使用圖形的生成操作調用導航方法時,目標片段正在&ldquo;創建&rdquo;但沒有出現,而起始片段就像已被停用一樣,但不會消失。我想我已經遵循了Google 文檔頁面上列出的所有步驟,但我可能遺漏了一些簡單的東西!這是我的依賴項:dependencies {? ? implementation fileTree(dir: 'libs', include: ['*.jar'])? ? implementation 'androidx.appcompat:appcompat:1.1.0'? ? implementation 'androidx.constraintlayout:constraintlayout:1.1.3'? ? // ViewModel and LiveData? ? def lifecycle_version = "2.1.0"? ? implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"? ? def nav_version = "2.1.0"? ? implementation "androidx.navigation:navigation-fragment:$nav_version"? ? implementation "androidx.navigation:navigation-ui:$nav_version"? ? implementation 'androidx.legacy:legacy-support-v4:1.0.0'? ? testImplementation 'junit:junit:4.12'? ? androidTestImplementation 'androidx.test:runner:1.2.0'? ? androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}主要活動在我的主要活動類中,我只是定義了ModelViewin OnCreate():public class MainActivity extends AppCompatActivity {? ? MealDataModel mealDataModel;? ?? ? @Override? ? protected void onCreate(Bundle savedInstanceState) {? ? ? ? super.onCreate(savedInstanceState);? ? ? ? setContentView(R.layout.activity_main);? ? ? ? // Create the model on create of the main activity? ? ? ? mealDataModel = ViewModelProviders.of(this).get(MealDataModel.class);? ? }}在我的主要活動布局中,我只使用 NavHostFragment:...<fragment? ? ? ? android:id="@+id/fragment2"? ? ? ? android:name="androidx.navigation.fragment.NavHostFragment"? ? ? ? android:layout_width="match_parent"? ? ? ? android:layout_height="match_parent"? ? ? ? app:defaultNavHost="true"? ? ? ? app:layout_constraintBottom_toBottomOf="parent"? ? ? ? app:layout_constraintEnd_toEndOf="parent"? ? ? ? app:layout_constraintStart_toStartOf="parent"? ? ? ? app:layout_constraintTop_toTopOf="parent"? ? ? ? app:navGraph="@navigation/nav_graph" />...
查看完整描述

2 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

這:

//?Inflate?the?layout?for?this?fragment
????????View?myView?=?inflater.inflate(R.layout.fragment_meal_cost,?container,?false);
????????mealDataModel?=?ViewModelProviders.of(getActivity()).get(MealDataModel.class);

只需要這樣:

//?Inflate?the?layout?for?this?fragment
????????View?myView?=?inflater.inflate(R.layout.fragment_tip_percent,?container,?false);
????????mealDataModel?=?ViewModelProviders.of(getActivity()).get(MealDataModel.class);

這里學到的教訓是在調試時仔細檢查過程的每一步!錯誤通常隱藏在顯而易見的地方。


查看完整回答
反對 回復 2023-07-28
?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

如果您使用數據綁定,請更改充氣機線這些線

mDataBinding=DataBindingUtil.inflate(getLayoutInflater(),R.layout.fragment_date_sheet, container, false);

mDataBinding= DataBindingUtil.inflate(inflater,R.layout.fragment_date_sheet, container, false);



查看完整回答
反對 回復 2023-07-28
  • 2 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號