我在我的應用程序中使用片段。這是我簡單地誇大一個XML文件中第一個片段:如何將片段從片段傳遞到片段
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,包含一個片段:
<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類:
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");
}
}
我不知道如何將Bundle arguments
從FragmentA傳遞給ListFrag。
public static ListFrag newInstance(int doctorId) {
ListFrag frag = new ListFrag();
Bundle args = new Bundle();
args.putExtra("doctor_id", doctorId);
frag.setArguments(args);
return frag;
}
當您從片段A一ListFrag,你會打電話:
Fragment frag = ListFrag.newInstance(this.doctor_id);
// use frag with getSupportChildFragmentManager();
我不是從FragmentA創建ListFrag ..我在XML文件中使用的片段,然後從膨脹A.片段是XML文件 – Vikky
黑帶然後下面,對你 – gunar
SRY解決....... .... 你什麼意思?? – Vikky