4
votes

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_main, container, false);

    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"
    };
    ArrayList<String> listforecast = new ArrayList<String>(Arrays.asList(data));


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item_forcast_,
            R.id.listitem_forcast_textview, listforecast);

    listView = (ListView) container.findViewById(R.id.listview_display);
    listView.setAdapter(adapter);

    return v;
} 

fragment.xml

<!-- TODO: Update blank fragment layout -->
<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listview_display"
    ></ListView>

1

1 Answers

5
votes

Replace:

listView = (ListView) container.findViewById(R.id.listview_display);

with

listView = (ListView) v.findViewById(R.id.listview_display);