Android列表视图不查看数组的元素

时间:2015-01-24 19:20:09

标签: java android

week_forecast数组包含应该出现在设计中的元素,但这不会发生 出现的是item1,item2,item3,....

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

        ArrayList<String> week_forecast = new ArrayList<String>();
        week_forecast.add("Today - Sunny - 88/630");
        week_forecast.add("Tomorrow - Foggy - 70/46");
        week_forecast.add("Weds - Cloudy - 72/63");
        week_forecast.add("Thurs - Rainy - 64/51");
        week_forecast.add("Fri - Foggy - 70/46");
        week_forecast.add("Sat - Sunny - 76/68");

        // initializing the adapter of the list of views
        adapter = new ArrayAdapter<String>(getActivity(),R.layout.List_item_forecast,R.id.list_item_forecast_textview,week_forecast);
        ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);

        listView.setAdapter(adapter);
        return rootView;
    }
* listview_forecast是listview

的主片段的id

* list_item_forecast是带有textview

的片段的名称

* list_item_forecast_textview是prev片段的ID

1 个答案:

答案 0 :(得分:0)

更改此

adapter = new ArrayAdapter<String>(getActivity(),R.layout.List_item_forecast,R.id.list_item_forecast_textview,week_forecast);

到这个

adapter = new ArrayAdapter<String>(getActivity(),R.layout.List_item_forecast,week_forecast);