google我看到很多聲明嵌套 Fragments的聲明不能使用 XML 。 現在我是Android的新手,但我的應用程序使用嵌套的Fragments 。 我還沒有讓監聽器和介面工作,( 也許這就是人們說你不能使用XML的原因),但是GUI工作。
我的問題:我所閱讀的關於不使用XML的嵌套 Fragments的註釋是什麼意思?
這裡是一個鏈接鏈接,指向一個聲明XML不能使用嵌套的Fragments:
下面的代碼創建 3 radiogroups ( 在 fragment 中) 水平排列在頂部( 在另一個 fragment 中),下面是一個 listview ( 在另一個 fragment 中) 。 Fragments 允許對不同顯示類型的查找進行良好的控制。
這是我的代碼:public class SetupNew extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ngs);
}}
ngs.xml
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:layout_height="250dp"
android:layout_width="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:name="com.EXAMPLE.frag_class_options_all"/>
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:name="com.EXAMPLE.frag_class_opponents"/>
frag_class_options_all.javapublic class frag_class_options_all extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.options_all, container, false);
return view;
}}
frag_class_opponents.javapublic class frag_class_opponents extends ListFragment implements LoaderManager.LoaderCallbacks {
//working contact listview
}
options_all.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:layout_height="fill_parent"
android:layout_width="80dp"
android:layout_marginRight="15dp"
android:name="com.EXAMPLE.frag_class_options"/>
android:layout_height="fill_parent"
android:layout_width="75dp"
android:layout_marginRight="15dp"
android:name="com.EXAMPLE.frag_class_limit_options"/>
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:name="com.EXAMPLE.frag_class_allow"/>
英鎊 frag_class_options,frag_class_limit_options英鎊和英鎊都遵循如下所示:public class frag_class_options extends Fragment{
RadioGroup radioGroup;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.options_m, container, false);
radioGroup = (RadioGroup) view.findViewById(R.id.rg_limit);
return view;
}
}