Mi Lugarcito
공공데이터 파싱예제 - 미세먼지 Android 앱 만들기 본문
미세먼지 Open API - 네트워크 통신 : Retrofit2
현재 위치 : FusedLocationProvider
지역 저장, 삭제 Realm
새로 고침 SwipeRefreshLayout
#뷰 만들기
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical"
tools:showIn="@layout/app_bar_main">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#000000"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
bundle.app에서 vectorDrawables.useSupportLibrary=true 추가하기
버전이 17이하로 낮을때는 (하위버전에서는 vector drawable 아이콘이 안나타남)
vectorDrawables.useSupportLibrary=true 추가해서
app:srcCompat="@drawable/ic_baseline_location_on_24" --> 사용가능하도록 만들어야한다.
(하위버전 이미지뷰는 src 가 아니라 srcCompat 사용해야한다.)
fragment_fine_dust.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh_layout"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
app:srcCompat="@drawable/ic_baseline_location_on_24"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="관측장소"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
/>
</LinearLayout>
<TextView
android:id="@+id/result_location_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingTop="8dp"
tools:text="수원시"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
app:srcCompat="@drawable/ic_baseline_access_time_24"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="관측시간"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
/>
</LinearLayout>
<TextView
android:id="@+id/result_time_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingTop="8dp"
tools:text="수원시"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
app:srcCompat="@drawable/ic_baseline_blur_on_24"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="미세먼지"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
/>
</LinearLayout>
<TextView
android:id="@+id/result_dust_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingTop="8dp"
tools:text="수원시"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
#SwipeRefreshLayout사용하려면
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" 라이브러리 추가하기
최신버전은 아래 링크에서 참조하기
developer.android.com/jetpack/androidx/releases/swiperefreshlayout
'API' 카테고리의 다른 글
KakaoMap - db 등록된 위도, 경도를 가지고 마커 클러스터러 사용하기 (0) | 2021.09.05 |
---|---|
Public API (0) | 2021.04.07 |
Postman으로 워크잡 공공데이터 api 값 가져와보기 (0) | 2021.02.10 |
API & http 통신 테스트를 위한 Postman 사용법 (Json, xml 등 파싱하기) (0) | 2021.02.10 |
공공데이터 파싱예제 - 날씨 기상청 (0) | 2021.01.29 |