Java 为什么args类不生成导航图片段?
我在我的android项目中使用导航组件。我已经启用了Gradle的类型安全args插件。这里是我的build.Gradle(app)文件 和我的build.gradle(项目)文件 我的导航图xml代码如下所示Java 为什么args类不生成导航图片段?,java,android,android-architecture-navigation,android-navigation-graph,android-studio-3.6.1,Java,Android,Android Architecture Navigation,Android Navigation Graph,Android Studio 3.6.1,我在我的android项目中使用导航组件。我已经启用了Gradle的类型安全args插件。这里是我的build.Gradle(app)文件 和我的build.gradle(项目)文件 我的导航图xml代码如下所示 即使在多次尝试构建项目之后,目标片段的args类也不会创建。 下面是我的代码片段,操作是在其中发起的(SignUpFragment) SignUpFragmentDirections.ActionSignUpFragmentToSignInFragment action =
即使在多次尝试构建项目之后,目标片段的args类也不会创建。下面是我的代码片段,操作是在其中发起的(SignUpFragment)
SignUpFragmentDirections.ActionSignUpFragmentToSignInFragment action =
SignUpFragmentDirections.actionSignUpFragmentToSignInFragment();
action.setEmail(email);
action.setPassword(password);
这里是片段(SignInFragment)的目标代码,我想在这里访问那些参数电子邮件和密码
SignInFragmentArgs.getArguments().getString()
//Set up the navigation for the appropriate action
Navigation.findNavController(v).navigate(action);
根据官方文件,SignInFragmentArgs代码应该在构建项目期间生成,但事实并非如此,我遇到了严重的麻烦,因为我想从SignUpFragment访问那些传递的参数电子邮件和密码,但我找不到SignInFragmentArgs类,这意味着它不是在构建过程中生成的。这里的任何人都需要解决方案。您的
元素需要在
类上,而不是
元素上-操作上的参数仅为它们指向的目标上已经存在的参数提供覆盖值
<?xml version="1.0" encoding="utf-8"?>
<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_graph"
app:startDestination="@id/signInFragment">
<fragment
android:id="@+id/signInFragment"
android:name="com.example.nibotransporti.Fragment.SignInFragment"
android:label="fragment_sign_in"
tools:layout="@layout/fragment_sign_in" >
<argument
android:name="email"
android:defaultValue="ten"
app:argType="string" />
<argument
android:name="password"
android:defaultValue="wen"
app:argType="string" />
<action
android:id="@+id/action_registration"
app:destination="@id/signUpFragment" />
<action
android:id="@+id/action_signInFragment_to_workerAnalyticsFragment"
app:destination="@id/workerAnalyticsFragment" />
</fragment>
<fragment
android:id="@+id/signUpFragment"
android:name="com.example.nibotransporti.Fragment.SignUpFragment"
android:label="fragment_sign_up"
tools:layout="@layout/fragment_sign_up">
<argument
android:name="email"
android:defaultValue="3"
app:argType="string" />
<action
android:id="@+id/action_signUpFragment_to_signInFragment"
app:destination="@id/signInFragment" />
</fragment>
<fragment
android:id="@+id/workerAnalyticsFragment"
android:name="com.example.nibotransporti.Fragment.WorkerAnalyticsFragment"
android:label="WorkerAnalyticsFragment"
tools:layout="@layout/fragment_woker_analytics"/>
<fragment
android:id="@+id/reportFragment"
android:name="com.example.nibotransporti.Fragment.ReportFragment"
android:label="fragment_stock"
tools:layout="@layout/fragment_stock" />
</navigation>
请注意,根据和,您绝对不应该将登录/注册作为图形的开始目标。
SignInFragmentArgs.getArguments().getString()
//Set up the navigation for the appropriate action
Navigation.findNavController(v).navigate(action);
<?xml version="1.0" encoding="utf-8"?>
<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_graph"
app:startDestination="@id/signInFragment">
<fragment
android:id="@+id/signInFragment"
android:name="com.example.nibotransporti.Fragment.SignInFragment"
android:label="fragment_sign_in"
tools:layout="@layout/fragment_sign_in" >
<argument
android:name="email"
android:defaultValue="ten"
app:argType="string" />
<argument
android:name="password"
android:defaultValue="wen"
app:argType="string" />
<action
android:id="@+id/action_registration"
app:destination="@id/signUpFragment" />
<action
android:id="@+id/action_signInFragment_to_workerAnalyticsFragment"
app:destination="@id/workerAnalyticsFragment" />
</fragment>
<fragment
android:id="@+id/signUpFragment"
android:name="com.example.nibotransporti.Fragment.SignUpFragment"
android:label="fragment_sign_up"
tools:layout="@layout/fragment_sign_up">
<argument
android:name="email"
android:defaultValue="3"
app:argType="string" />
<action
android:id="@+id/action_signUpFragment_to_signInFragment"
app:destination="@id/signInFragment" />
</fragment>
<fragment
android:id="@+id/workerAnalyticsFragment"
android:name="com.example.nibotransporti.Fragment.WorkerAnalyticsFragment"
android:label="WorkerAnalyticsFragment"
tools:layout="@layout/fragment_woker_analytics"/>
<fragment
android:id="@+id/reportFragment"
android:name="com.example.nibotransporti.Fragment.ReportFragment"
android:label="fragment_stock"
tools:layout="@layout/fragment_stock" />
</navigation>