我创建了一个包含 5 个片段的活动,其中一个片段包含一个个人资料页面,我创建了另一个活动来编辑个人资料页面,但是当我单击保存按钮返回到编辑(片段)时。应用程序崩溃.. 我需要帮助或建议
这是我下面的片段代码:
public class MeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.me, container, false);
Button bt = (Button) view.findViewById(R.id.btedit);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getActivity(), Editme.class);
startActivity(i);
}
});
return view;
}
这是 Editme 类:
Button btnLoad = (Button) findViewById(R.id.btsave);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
MeFragment save = new MeFragment();
fragmentTransaction.add(R.id.fragment_content, save);
fragmentTransaction.commit();
}
};
btnLoad.setOnClickListener(listener);