我正在打开一个对话范围和捆绑数据。我不确定为什么,但是捆绑的数据似乎并没有过去。我在这里寻找了一个解决方案,但看不到我在做错什么:
这就是我打开片段并附加捆绑数据的方式:
FragmentManager fm = ((MainActivity)context).getSupportFragmentManager();
InfoFragment infoFragment = new InfoFragment();
Bundle bundle = new Bundle();
bundle.putString("TITLE", reminder.getReminderTitle());
bundle.putString("DESCRIPTION", reminder.getReminderDescription());
infoFragment.setArguments(bundle);
// Show DialogFragment
infoFragment.show(fm, "InfoFragment");
,在片段中,我正在检索捆绑的数据:
public class InfoFragment extends DialogFragment implements View.OnClickListener{
TextView titleTextView;
TextView descriptionTextView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_info, container,false);
// Iniate ui element
titleTextView = view.findViewById(R.id.infoFragmentTitleTextView);
descriptionTextView = view.findViewById(R.id.infoFragmentDescriptionTextView);
// Get the bundled reminder info to display
String title = getArguments().getString("TITLE");
String description = getArguments().getString("DESCRIPTION");
//Set the values for the textviews from the bundled data
titleTextView.setText(title);
descriptionTextView.setText(description);
return view;
我已经在活动中写下了以下代码,并将对话框中的代码保留在与您的对话框片段中,并且它的工作正常
FragmentManager fm = getSupportFragmentManager();
InfoFragment infoFragment = new InfoFragment();
Bundle bundle = new Bundle();
bundle.putString("TITLE", "Your title");
bundle.putString("DESCRIPTION", "Your description");
infoFragment.setArguments(bundle);
// Show DialogFragment
infoFragment.show(fm, "InfoFragment");
您能告诉我您在哪里编写代码以打开片段