如何通过扎片段片段 [英] how pass Bundle From Fragment to Fragment
本文介绍了如何通过扎片段片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用的片段在我的应用程序。这是我的IST片段只是夸大一个xml文件。
i am using fragments in my application. this is my ist fragment that simply inflate a xml file..
public class FragmentA extends SherlockFragment
{
Context myContext,appContext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
myContext = getActivity();
appContext=getActivity().getApplicationContext();
arguments = getArguments();
doctor_id=arguments.getInt("doctor_id");
userType=arguments.getString("userType");
return inflater.inflate(R.layout.left_panel, container,false);
}
和这是left_panel的.xml ..它含有的片段
and this is the left_panel .xml.. it contains a fragment
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/titles"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.example.sample.ListFrag" />
</LinearLayout>
这是我listFrag类
and this is my listFrag class
public class ListFrag extends Fragment
{
Context myContext,appContext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
layoutView = inflater.inflate(R.layout.activity_doctor_list,container);
myContext = getActivity();
appContext=getActivity().getApplicationContext();
arguments=getArguments();
int doctor_id=arguments.getInt("doctor_id");
}
}
在这里,我不知道如何传递捆绑参数
从碎裂到ListFrag
here i dont know how pass Bundle arguments
from FragmentA to ListFrag
推荐答案
在您的碎裂片段设置包作为参数。</ P>
In your FragmentA fragment set the bundle as the argument.
Bundle args = new Bundle();
args.putInt("doctor_id",value);
ListFrag newFragment = new ListFrag ();
newFragment.setArguments(args);
在你ListFrag片段让包作为
In your ListFrag fragment get the bundle as
Bundle b = getArguments();
String s = b.getInt("doctor_id");
这篇关于如何通过扎片段片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文