Hello. How was your holiday? I'd like to ask you a question that I couldn't solve during the holidays.
I constructed a view page using three tabs in the layout.
In fragment tab A, enter the string value using EditText and press the button below.
Use the bundle to set the value to the main class surrounding the tab.
If the value remains in TextView in fragment tab B, it is stored continuously and again in tab A
You want to change the value when you enter a different value and press the button.
There's a way to google and make it successful, and when you flip the tab, the overall performance is
It's getting too slow, so I'm looking for another way.
For the current source, the previous input value is displayed when the app is shut down and turned on again.
However, it does not update immediately when you close the tab after entering it.
I would appreciate it if you could answer me if you know any examples that are similarly implemented or if you know anything.
Attached is the relevant source below.
// Inside the click event listener in fragment tab A
childDate = childBirth.getText().toString();
Bundle arguments = new Bundle();
arguments.putString("name", childDate);
MainTab.setArguments(arguments);
// Main Class Getter Setter
public static void setArguments(Bundle arguments) {
MainTab.arguments = arguments;
}
public static Bundle getArguments() {
return arguments;
}
// Fragments Tab BonCreateView
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_educationinfo, container, false);
Bundle bundle = MainTab.getArguments();
if (bundle != null) {
String name = bundle.getString("name");
TextView txt = (TextView) v.findViewById(R.id.test);
txt.setText(name);
}
return v;
}
If you look at the code you uploaded, the setArguments() function is used to deliver the value. This function is available only before the fragment is attached to the activity. In other words, it is used to pass parameters when generating fragments. A value cannot be passed to an already created fragment.
If I summarize the question one more time, I understood that I want to pass the data from fragment A to fragment B, but it doesn't work well. If so, please read the link below and use the viewpager to access the fragments directly.
© 2024 OneMinuteCode. All rights reserved.