Skip to content

Commit

Permalink
练习:修复应用
Browse files Browse the repository at this point in the history
  • Loading branch information
heyblood committed Jan 24, 2021
1 parent 0f1fc16 commit 46d6463
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/src/main/java/com/example/didyoufeelit/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.example.didyoufeelit;

import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;

Expand All @@ -37,11 +38,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Perform the HTTP request for earthquake data and process the response.
Event earthquake = Utils.fetchEarthquakeData(USGS_REQUEST_URL);
EarthquakeAsyncTask task = new EarthquakeAsyncTask();
task.execute(USGS_REQUEST_URL);

// Update the information displayed to the user.
updateUi(earthquake);
}

/**
Expand All @@ -58,4 +57,19 @@ private void updateUi(Event earthquake) {
magnitudeTextView.setText(earthquake.perceivedStrength);
}

private class EarthquakeAsyncTask extends AsyncTask<String, Void, Event> {
@Override
protected Event doInBackground(String... urls) {
// Perform the HTTP request for earthquake data and process the response.
Event earthquake = Utils.fetchEarthquakeData(USGS_REQUEST_URL);
return earthquake;
}

@Override
protected void onPostExecute(Event result) {
// Update the information displayed to the user.
updateUi(result);
}
}

}

0 comments on commit 46d6463

Please sign in to comment.