-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First Android App codelab: TASK 9 #80
Comments
hey there, I tried your steps but didn't end up with any solution for my problem as I didn't change anything |
Follow Step 6: Create the argument for the navigation action The text is NOT clear, I made the same mistake like you did. I try to find "Add Argument dialog" first in "SecondFragment.kt" since the text said "Click on SecondFragment" but I can't find "Add Argument dialog" , then I look at " fragment_second.xml" then " FirstFragment.kt" then "fragment_first.xml" then I asked a person who knows kotlin and he didn't know why there was this "Too many arguments" problem. This problem took me a week to solve by myself and people can call me stupid since the text saide "In the navigation graph" but for a total beginner, it is better off the professional who wrote this task can write it more clearly. "In the nav_graph.xml" is more clear than "In the navigation graph". Hopefull this will help you. |
Thanks for the reply but things just got messed up for me now, I am writing the code using java not using Kotlin so if I didn't understand you right check my repo for the app and tell me specifically in what file and where to fix my error |
Didn't help me though *( |
OMG, Your Last sentence helps me a lot. The error showed only because I add argument in nav_graph to the First Fragement which should have been added to the Second Fragement. Thank you @mikalaikarol |
Thank you, @Lifshatz! For me the app-level
|
It's possible I made a mistake or perhaps there's an error with the instructions. Either way, I am looking for some help with this: https://developer.android.com/codelabs/build-your-first-android-app?hl=tr#8
Step 7: Send the count to the second fragment
The Next/Random button was set up by Android Studio to go from the first fragment to the second, but it doesn't send any information. In this step you'll change it to send a number for the current count. You will get the current count from the text view that displays it, and pass that to the second fragment.
Open FirstFragment.java (app > java > com.example.myfirstapp > FirstFragment)
Find the method onViewCreated() and notice the code that sets up the click listener to go from the first fragment to the second.
Replace the code in that click listener with a line to find the count text view, textview_first.
int currentCount = Integer.parseInt(showCountTextView.getText().toString());
Create an action with currentCount as the argument to actionFirstFragmentToSecondFragment().
FirstFragmentDirections.ActionFirstFragmentToSecondFragment action = FirstFragmentDirections.actionFirstFragmentToSecondFragment(currentCount);
Add a line to find the nav controller and navigate with the action you created.
NavHostFragment.findNavController(FirstFragment.this).navigate(action);
Here is the whole method, including the code you added earlier:
public void onViewCreated(@nonnull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.random_button).setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
int currentCount = Integer.parseInt(showCountTextView.getText().toString());
FirstFragmentDirections.ActionFirstFragmentToSecondFragment action = FirstFragmentDirections.actionFirstFragmentToSecondFragment(currentCount);
NavHostFragment.findNavController(FirstFragment.this).navigate(action);
}
});
view.findViewById(R.id.toast_button).setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
Toast myToast = Toast.makeText(getActivity(), "Hello toast!", Toast.LENGTH_SHORT);
myToast.show();
}
});
view.findViewById(R.id.count_button).setOnClickListener(new View.OnClickListener() {



@OverRide
public void onClick(View view) {
countMe(view);
}
});
}
The text was updated successfully, but these errors were encountered: