通过捆绑包传递时在途中丢失数据,我得到
尝试在 String bundlePassData = this.getArguments().getString(“tagName”) 上的空对象引用上调用虚拟方法 'java.lang.String.String android.os.bundle.getString(java.lang.String)'
这是我的代码示例。主要活动->
tagsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Bundle bundle = new Bundle();
TextView textView = (TextView) view.findViewById(R.id.tagName);
String selectedItemName = textView.getText().toString();
bundle.putString("tagName", selectedItemName);
TaskAssignFragment taskAssignFragment = new TaskAssignFragment();
taskAssignFragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.commit();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new TaskAssignFragment()).addToBackStack(null).commit();
Log.i("ListView", selectedItemName);
}
});
TaskAssignFragment->
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_task_assign, container, false);
TextView test = view.findViewById(R.id.testerView);
String bundlePassData = this.getArguments().getString("tagName");
test.setText(bundlePassData);
return view;
}
我应该试试吗?但是,如果我需要将数据作为变量,而不仅仅是在函数中,因为我会在.interfacesfragment
守着星空守着你
茅侃侃
慕工程0101907
慕村225694
相关分类