I have a question about delivering

Asked 2 years ago, Updated 2 years ago, 96 views

In the main activity

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        String comment = data.getStringExtra("comment");
        int rating = Math.round(data.getFloatExtra("rating", 0.0f));
        if (comment != null) {
            Bundle bundle = new Bundle();
            bundle.putString("comment",comment);
            bundle.putInt("rating", rating);
            movieDetailFragment.setArguments(bundle);
        }
    }
}

In the fragment that sends and receives data in this way, we organize the code in this way for Listview renewal, but it is not updated Is there a problem?

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.movie_detail_fragment, container, false);

    Bundle bundle1 = getArguments();
    if (bundle1 != null) {
        String comment = bundle1.getString("comment");
        int rating = bundle1.getInt("rating");
        items.add(new CommentItems("kim78**", rating, comment, R.drawable.user1));
        adapter.notifyDataSetChanged();
    }

bundle fragment activity android

2022-09-22 12:16

1 Answers

If you have an instance of the fragment in Activity, you can run the method of the fragment immediately when the onActivityResult() in Activity is called. You can also override onActivityResult() in Fragment


2022-09-22 12:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.