对话框片段包不传递数据
Dialog fragment bundle not passing data
我正在打开一个对话框片段并捆绑数据。我不确定为什么,但捆绑数据似乎并没有过去。我在这里寻找解决方案,但我看不出我做错了什么:
这是我打开片段并附加捆绑数据的方式:
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;
我已经在我的 activity 中编写了以下代码,并在对话框片段中保留了与您的代码相同的代码,并且它工作得很好
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");
你能告诉我你在哪里写了代码来打开你的片段吗
我正在打开一个对话框片段并捆绑数据。我不确定为什么,但捆绑数据似乎并没有过去。我在这里寻找解决方案,但我看不出我做错了什么:
这是我打开片段并附加捆绑数据的方式:
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;
我已经在我的 activity 中编写了以下代码,并在对话框片段中保留了与您的代码相同的代码,并且它工作得很好
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");
你能告诉我你在哪里写了代码来打开你的片段吗