Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.quakereport; | ||
|
||
public class Earthquake { | ||
private String mag; | ||
private String place; | ||
private String time; | ||
|
||
public String getMag() { | ||
return mag; | ||
} | ||
|
||
public String getPlace() { | ||
return place; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
|
||
public Earthquake(String mag, String place, String time) { | ||
this.mag = mag; | ||
this.place = place; | ||
this.time = time; | ||
} | ||
} |
This file contains 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
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/example/quakereport/EarthquakeAdapter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.quakereport; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class EarthquakeAdapter extends ArrayAdapter<Earthquake> { | ||
|
||
public EarthquakeAdapter(@NonNull Context context, @NonNull List<Earthquake> objects) { | ||
super(context, 0, objects); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
View itemView = convertView; | ||
Earthquake earthquake; | ||
ViewHolder holder; | ||
|
||
if (null == itemView) { | ||
itemView = LayoutInflater.from(getContext()).inflate(R.layout.earthquake_item, null); | ||
holder = new ViewHolder(); | ||
holder.tvMag = itemView.findViewById(R.id.mag_text); | ||
holder.tvPlace = itemView.findViewById(R.id.place_text); | ||
holder.tvTime = itemView.findViewById(R.id.time_text); | ||
itemView.setTag(holder); | ||
} else { | ||
holder = (ViewHolder) itemView.getTag(); | ||
} | ||
|
||
earthquake = getItem(position); | ||
|
||
holder.tvMag.setText(earthquake.getMag()); | ||
holder.tvPlace.setText(earthquake.getPlace()); | ||
holder.tvTime.setText(earthquake.getTime()); | ||
|
||
return itemView; | ||
} | ||
|
||
private static class ViewHolder { | ||
private TextView tvMag; | ||
private TextView tvPlace; | ||
private TextView tvTime; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:padding="@dimen/dp_16"> | ||
|
||
<TextView | ||
android:id="@+id/mag_text" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
tools:text="8.0" /> | ||
|
||
<TextView | ||
android:id="@+id/place_text" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="3" | ||
tools:text="Wenchuan Sichuan" /> | ||
|
||
<TextView | ||
android:id="@+id/time_text" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="2" | ||
android:gravity="right" | ||
tools:text="May 12, 2008" /> | ||
|
||
</LinearLayout> |