大佬教程收集整理的这篇文章主要介绍了android – 如何将Bundle传递给Fragment,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public void onItemClick(AdapterView<?> parent,View view,int position,long id) { Intent choice = new Intent(getApplicationContext(),com.MyProject.project.MyList.class); Bundle dataBundle = new Bundle(); String chosenValue = values[position]; dataBundle.putString("Level",chosenvalue); choice.putExtras(dataBundlE); startActivity(choicE); }
现在这是我没有Bundle的活动.这很好用:
public void onActivityCreated(Bundle savedInstanceStatE) { super.onActivityCreated(savedInstanceStatE); String[] values = new String[] { "Enterprise","Star Trek","Next Generation","Deep Space 9","Voyager"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,values); setlistadapter(adapter); }
但是,当我尝试从Bundle获取信息时,它不起作用.这是我的代码:
public void onActivityCreated(Bundle savedInstanceStatE) { super.onActivityCreated(savedInstanceStatE); Bundle info = getArguments(); String level = info.getString("level"); String[] values = new String[] {level,level}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),values); setlistadapter(adapter); }
当我运行它并在我的Activity中单击我的选择时,应用程序就会挂起. LogCat似乎没有给我很多关于此的信息.有没有人在这看到任何问题?
谢谢!
以上是大佬教程为你收集整理的android – 如何将Bundle传递给Fragment全部内容,希望文章能够帮你解决android – 如何将Bundle传递给Fragment所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。