Имеется activity c одним фрагментом, который добавляется через xml.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<fragment
android:name="localhost.myweatherapp.ForecastFragment"
android:id="@+id/forecast_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Layout фрагмента.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_view_forecast"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</FrameLayout>
И метод onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Create some dummy data for the ListView. Here's a sample weekly forecast
String[] data = {
"Mon 6/23 - Sunny - 31/17",
"Tue 6/24 - Foggy - 21/8",
"Wed 6/25 - Cloudy - 22/17",
"Thurs 6/26 - Rainy - 18/11",
"Fri 6/27 - Foggy - 21/10",
"Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
"Sun 6/29 - Sunny - 20/7"
};
List<String> weekForecastData = new ArrayList<String>(Arrays.asList(data));
ArrayAdapter forecastAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item_forecast, R.id.list_item_forecast_textview, weekForecastData);
ListView forecastListView = (ListView)container.findViewById(R.id.list_view_forecast);
forecastListView.setAdapter(forecastAdapter);
return inflater.inflate(R.layout.forecast_fragment, container, false);
}
Так вот по непонятным для меня причинам аргумент container равен null.