Reputation: 121
i want to send multiple bundles from activity to fragment, the problem i'm facing here is bundle 2 get the reference of bundle 1, how to differentiate both the bundles. please provide me some suggestion.
Here is what i pass from activity to fragment,
FeatureTab featureTab = new FeatureTab();
featureTab.setArguments(bundle_DescriptioneTab);
featureTab.setArguments(bundle_User_Review);
fragmentTransaction.replace(R.id.tabcontainer, featureTab, "FeatureTab");
fragmentTransaction.commit();
Here is what i used in fragments to get the bundle,
Bundle 1 :
private void setDescription() {
try {
Bundle bundle = getArguments();
txt_Description.setText(bundle.getString("long_description"));
} catch (NullPointerException e) {
AppUtils.logError(TAG, "NullPointerException");
}
}
Bundle 2:
private void getUserReviewsParcel() {
try {
Bundle bundle = this.getArguments();
UserReviewsParcel userReviewsParcel = bundle.getParcelable("user_reviews");
List<UserReviewsBean> list = userReviewsParcel.getparcelList();
// set the listview adapter
setListviewAdapter(list);
} catch (NullPointerException e) {
AppUtils.logError(TAG, "NullPointerException");
}
}
i'm calling both the methods in onCreateView.
Upvotes: 1
Views: 1973
Reputation: 132992
How to send multiple bundles from activity to fragment
Use Bundle.putBundle(KEY,VALUE) to prepare a bundle which contains other bundles and you can access using keys:
Bundle bundle=new Bundle();
bundle.putBundle("bundle_DescriptioneTab",bundle_DescriptioneTab);
bundle.putBundle("bundle_User_Review",bundle_User_Review);
Pass bundle
to setArguments
method and you can access both Bundle using bundle_DescriptioneTab
and bundle_User_Review
keys.
Upvotes: 1