我有这堂课:
public class list extends ListFragment {
String[] countries = new String[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
"Nepal",
"Afghanistan",
"North Korea",
"South Korea",
"Japan"
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(), android.R.layout.simple_list_item_1,countries);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
}
更新:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.FoodOrderApp.MainActivity$PlaceholderFragment"
android:padding="0dp">
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabHost"
android:layout_alignParentTop="true"
android:layout_margin="0dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/all_dishes"
android:name="com.FoodOrderApp.list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/fav_dishes"
android:name="com.FoodOrderApp.list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
我希望在onCreateView方法中获取当前列表片段的id
答案 0 :(得分:0)
您可以使用:
ListView lV = getListView();
要获取当前列表的ID,如果您要手动执行,请在 ListFragment 或 ListActivity 中获取android.R.id.list
。