我的应用程序中有 3 个 sherlockListFragments。每个片段都有一些editTexts,最后一个片段有一个按钮,当它被按下时,第一个和第二个片段中的所有数据都应该被访问和存储。我使用 bundle 在片段之间发送数据。使用以下简单示例,这是我的第一个片段的代码:
public class PersonalDataFragment extends SherlockListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragmet_personal_data, container, false);
return v;
}
@Override
public void onCreate(Bundle savedInstanceState) {
PersonalDataFragment fragment = new PersonalDataFragment();
Bundle bundle = new Bundle();
bundle.putString("y", "koko"); //any string to be sent
fragment.setArguments(bundle);
super.onCreate(savedInstanceState);
}
这是接收文本的片段的代码:
public class WorkExpRefFragment extends SherlockListFragment {
String myInt;
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_workexp_ref, container, false);
final EditText t = (EditText) view.findViewById(R.id.editText5);
final Button generate = (Button)view.findViewById(R.id.button2);
generate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
t.setText(myInt + "sadfigha");
}
});
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
Bundle bundle = this.getArguments();
if(getArguments()!=null) {
myInt = getArguments().getString("y");
}
super.onCreate(savedInstanceState);
}
}
现在我在第三个片段中有一个空值,我该怎么办?提前致谢