I use Volley and Gson to get the data. I want to transfer the data I received from the main activity to the Fragment containing ViewPager I put data as Budle in Viewpager Fragment and receive it as getArgument at the time Viewpager Fragment becomes OnCreateView, but I keep getting nullpoint errors... Why is that?
public void processRespons(String response) {
Gson gson = new Gson();
ResponseInfo info = gson.fromJson(response, ResponseInfo.class);
MovieList movieList = gson.fromJson(response, MovieList.class);
if (info.code == 200) {
MovieInfo movieInfo = movieList.result.get(1);
String title = movieInfo.title;
Bundle bundle = new Bundle();
bundle.putString("title", title);
ViewPager1 viewPager = new ViewPager1();
viewPager.setArguments(bundle);
}
}
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = (ViewGroup) inflater.inflate(R.layout.view_pager1, container, false);
Button button = rootView.findViewById(R.id.viewpager1_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = getArguments();
String title = bundle.getString("title");
TextView text = rootView.findViewById(R.id.viewpager1_title);
text.setText(title);
}
});
ViewPager1 viewPager1();
viewPager.setArguments(bundle);
Are we going to create a new fragment object and finish with setArguments? Even if you do setArguments, I think you should put it in the fragment object bound to ViewPager. If you look at the two lines of code in that situation, it seems to be meaningless
If the number of fragments is set, you can send the value to the fragment and update it directly, or you can request http from the fragment in the first place. There is also a way to implement it in response to notifyDataSetChanged() in the fragment adapter. I don't know the whole flow, so it's hard to give you detailed advice
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
581 PHP ssh2_scp_send fails to send files as intended
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.