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
Step 1: | |
Go to: C:\Windows\System32\Drivers\etc\hosts | |
And add this to the bottom of the file: | |
============= | |
127.0.0.1 your.domain.com | |
============= | |
Step 2: | |
Go to [your XAMPP directory]/apache/conf/httpd-xampp.conf |
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
forecastListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
String forecastValue= (String) parent.getItemAtPosition(position); | |
Toast.makeText(getActivity(),forecastValue,Toast.LENGTH_LONG).show(); | |
} | |
}); |
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
urlConnection = (HttpURLConnection) url.openConnection(); | |
urlConnection.setRequestMethod("GET"); | |
urlConnection.connect(); | |
// Read the input stream into a String | |
InputStream inputStream = urlConnection.getInputStream(); | |
StringBuffer buffer = new StringBuffer(); | |
if (inputStream == null) { | |
// Nothing to do. | |
return null; |
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
URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7"); | |
final String FORECAST_BASE_URL = | |
"http://api.openweathermap.org/data/2.5/forecast/daily?"; | |
final String QUERY_PARAM = "q"; | |
final String FORMAT_PARAM = "mode"; | |
final String UNITS_PARAM = "units"; | |
final String DAYS_PARAM = "cnt"; | |
Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon() |
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
public class FetchWeatherTask extends AsyncTask<String, Void, String[]> { | |
private final String LOG_TAG = FetchWeatherTask.class.getSimpleName(); | |
/* The date/time conversion code is going to be moved outside the asynctask later, | |
* so for convenience we're breaking it out into its own method now. | |
*/ | |
private String getReadableDateString(long time) { | |
// Because the API returns a unix timestamp (measured in seconds), | |
// it must be converted to milliseconds in order to be converted to valid date. |
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
ListView forecastListView; | |
View view = inflater.inflate(R.layout.fragment_main, container, false); | |
String[] forecastData = {"Sunny", "Cloudy", "Warm", "Hot", "Cold"}; | |
List<String> forecastList = new ArrayList<String>(Arrays.asList(forecastData)); | |
forecastAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(), | |
R.layout.list_item_forecast, R.id.list_item_forecast_textView, forecastList); | |
forecastListView = (ListView) view.findViewById(R.id.listView_forecast); |