我正在构建一个包含2个片段的视图。充气布局工作正常。但我有另一个问题。在创建这些片段之前,我需要将一些数据传递给这些片段(FragmentListSchema和FragmentSchemaDetail)。我想到了应用程序变量,但我想这不是正确的方法。我该怎么做 ? 在此先感谢将数据传递给多个片段
膨胀:
public class FragmentSchemaTotal extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.fragment_schema,container);
return view;
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment android:name="kine.gui.FragmentListSchema"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="kine.gui.FragmentSchemaDetail"
android:id="@+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
感谢您的回答。也许不清楚,我需要将数据传递给FragmentListSchema和FragmentSchemaDetail。有任何想法吗 ?谢谢 – David
你需要从布局xml传递数据吗? – Libin
我需要将数据从FragmentSchemaTotal传递给FragmentListSchema和FragmentSchemaDetail,它们在XML中定义并创建,但我不知道如何将数据传递给这些片段。 – David