public class EarthquakeActivity extends AppCompatActivity {
public static final String LOG_TAG = EarthquakeActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.earthquake_activity);
// Create a fake list of earthquake locations.
// ArrayList<String> earthquakes = new ArrayList<>();
// earthquakes.add("San Francisco");
// earthquakes.add("London");
// earthquakes.add("Tokyo");
// earthquakes.add("Mexico City");
// earthquakes.add("Moscow");
// earthquakes.add("Rio de Janeiro");
// earthquakes.add("Paris");
// ArrayList<Earthquake> earthquakes = new ArrayList<Earthquake>();
// earthquakes.add(new Earthquake("6.2", "London", "22/11/2012"));
// earthquakes.add(new Earthquake("2.6", "New York", "14/11/2011"));
// earthquakes.add(new Earthquake("3.3", "Boston", "12/11/2013"));
// earthquakes.add(new Earthquake("2.7", "Madrid", "26/11/2015"));
// earthquakes.add(new Earthquake("1.8", "Chicago", "14/11/2010"));
ArrayList<Earthquake> earthquakes = QueryUtils.extractEarthquakes();
// Find a reference to the {@link ListView} in the layout
ListView earthquakeListView = (ListView) findViewById(R.id.list);
// Create a new {@link ArrayAdapter} of earthquakes
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(
// this, android.R.layout.simple_list_item_1, earthquakes);
final EarthQuakeAdapter earthAdapter = new EarthQuakeAdapter(this, earthquakes);
// Set the adapter on the {@link ListView}
// so the list can be populated in the user interface
earthquakeListView.setAdapter(earthAdapter);
earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Earthquake currentEarthquake = earthAdapter.getItem(i);
Uri earthquakeUri = Uri.parse(currentEarthquake.getUrl());
Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);
startActivity(websiteIntent);
}
});
}
}