Skip to content

Commit

Permalink
加载指示符
Browse files Browse the repository at this point in the history
  • Loading branch information
heyblood committed Jan 26, 2021
1 parent 6a693e5 commit d837afe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class EarthquakeActivity extends AppCompatActivity implements LoaderManag
* URL for earthquake data from the USGS dataset
*/
private static final String USGS_REQUEST_URL =
"https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&orderby=time&minmag=5&limit=0";
"https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&orderby=time&minmag=5&limit=15";

/**
* 地震列表的适配器
Expand Down Expand Up @@ -127,6 +128,10 @@ public void onLoadFinished(@NonNull Loader<List<Earthquake>> loader, List<Earthq
// Set empty state text to display "No earthquakes found."
emptyView.setText(R.string.no_earthquakes);

// 因数据已加载,隐藏加载指示符
ProgressBar progressBar = findViewById(R.id.loading_spinner);
progressBar.setVisibility(View.GONE);

// 清除之前地震数据的适配器
earthquakeAdapter.clear();

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/earthquake_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAppearance="?android:textAppearanceMedium" />

<!-- Loading spinner is only shown before the first load -->
<ProgressBar
android:id="@+id/loading_spinner"
style="?android:progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />

</RelativeLayout>

0 comments on commit d837afe

Please sign in to comment.