Created
January 2, 2015 04:32
-
-
Save msomu/06436716a85e6bdfb15e to your computer and use it in GitHub Desktop.
How to create a list view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| View rootView = inflater.inflate(R.layout.fragment_main, container, false); | |
| //Once the root view for the fragment has been created | |
| //the ListView with some dummy data | |
| //Create some dummy data for the list view | |
| String [] forecastArray = { | |
| "Today - Sunny - 88/63", | |
| "Tomorrow -Foggy - 70/40", | |
| "Weds - Clody - 72/63", | |
| "Fri - Heavy Rain - 65/56", | |
| "Sat - HELP TRAPPED IN WEATHERSTATION - 60/51", | |
| "Sun - Sunny - 80/68", | |
| }; | |
| List<String> weekForecast = new ArrayList<>( | |
| Arrays.asList(forecastArray) | |
| ); | |
| //Now that we have some dummy forecast data, create an ArrayAdapter. | |
| //The ArrayAdapter will take data from a source (like our dummy forecast) | |
| //use it to populate the ListView it's attached to. | |
| mForecastAdapter = new ArrayAdapter<String>( | |
| //The current context (this fragment's parent activity) | |
| getActivity(), | |
| //ID of the list item layout | |
| R.layout.list_item_forecast, | |
| //ID of the textview to populate | |
| R.id.list_item_forecast_textview, | |
| //Forecast data | |
| weekForecast | |
| ); | |
| //Get a reference to the ListView, and attach it to this adapter | |
| ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); | |
| listView.setAdapter(mForecastAdapter); | |
| return rootView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment