【发布时间】:2018-09-21 09:14:17
【问题描述】:
java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
mBtHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.homePageFragment);
}
});
startDestination 片段内的 mBtHome 按钮
导航图xml文件。
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_file"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/mainFragment"
android:name="com.example.libin.navigationhelphertest.ui.main.MainFragment"
android:label="main_fragment"
tools:layout="@layout/main_fragment">
<action
android:id="@+id/action_mainFragment_to_homePageFragment"
app:destination="@id/homePageFragment" />
<action
android:id="@+id/action_mainFragment_to_usersListFragment"
app:destination="@id/usersListFragment" />
</fragment>
<fragment
android:id="@+id/homePageFragment"
android:name="com.example.libin.navigationhelphertest.ui.main.HomePageFragment"
android:label="fragment_home_page"
tools:layout="@layout/fragment_home_page" />
<fragment
android:id="@+id/usersListFragment"
android:name="com.example.libin.navigationhelphertest.ui.main.UsersListFragment"
android:label="fragment_users_list"
tools:layout="@layout/fragment_users_list" />
</navigation>
在 MainActivity xml 文件中添加了导航/导航文件 NavHostFragment 也包括在内,还添加了 defaultNavHost= "true"
【问题讨论】:
-
您能否发布您的导航图 xml 文件?
-
@Android_team 用 xml 编辑
-
所以从您的 MainFragment 开始,您正在执行此代码并导航到 Home Fragemt right ?mBtHome.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Navigation.findNavController(getActivity (), R.id.homePageFragment); } });
-
就是这样。我有两个动作
-
@LibinThomas 你得到答案了吗?
标签: android navigationcontroller android-jetpack android-architecture-navigation