- [Android] 개발공부 46일차 TIL - spinner , BuildConfig import 불가에러, Map과 HashMap, 서버통신에러2024년 01월 24일 12시 50분 15초에 업로드 된 글입니다.작성자: 짧은 코딩끈
일자 : 2024.01.24
📝TIL 정리
💬Spinner
Spinner의 가장 기본 형태를 구현하고자 연습을 해보았다
main.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".MainActivity"> <Spinner android:id="@+id/sp_view" android:layout_width="match_parent" android:layout_height="50dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:entries="@array/testlist"/> <TextView android:id="@+id/tv_result" android:layout_width="match_parent" android:layout_height="0dp" android:hint="Hello World!" android:textSize="25sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/sp_view" /> </androidx.constraintlayout.widget.ConstraintLayout>
array.xml
기본적으로 리스트를 담아두기 위해
array resouce 파일을 생성한뒤에 목록에 들어갈 각 아이템 이름을 작성해준다
array 이름도 정해두어야 참조가능하다
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="testlist"> <item>손오공</item> <item>베지터</item> <item>크리링</item> <item>인조인간16호</item> <item>야무치</item> </string-array> </resources>
MainActivity.kt
스피너에 관한 선택 이벤트 핸들러를 정의하려면 AdapterView.OnItemSelectedListener 인터페이스와 이에 상응하는 onItemSelected() 콜백 메서드를 구현
선택되었을 떄와 선택되지 않았을 떄 2가지 경우에 대해서 구현해야하지만
이번에는 선택되었을 때만 사용
선택된아이템의 이름값과 위치값을 받아서 TextView에 뿌리도록하였다.
class MainActivity : AppCompatActivity() { private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(binding.root) with(binding){ spView.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long ) { tvResult.text = "선택한 친구는 : ${spView.selectedItem}\n" + "위치는 : ${spView.selectedItemPosition}" } override fun onNothingSelected(parent: AdapterView<*>?) { } } } } }
https://developer.android.com/guide/topics/ui/controls/spinner?hl=ko
스피너 | Android 개발자 | Android Developers
스피너 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 스피너는 값 집합에서 하나의 값을 선택할 수 있는 빠른 방법을 제공합니다. 기본 상태의 스피너는
developer.android.com
https://github.com/skydoves/PowerSpinner
GitHub - skydoves/PowerSpinner: 🌀 A lightweight dropdown popup spinner, fully customizable with an arrow and animations for A
🌀 A lightweight dropdown popup spinner, fully customizable with an arrow and animations for Android. - GitHub - skydoves/PowerSpinner: 🌀 A lightweight dropdown popup spinner, fully customizable wit...
github.com
⛔BuildConfig import 불가에러
네트워크 통신을 통해
공공데이터 포털에서 제공해주는 데이터를 받아서 처리하는 코드를 연습중이었는데(retrofit, json, gson 등등)
관련 코드중에 BuildConfig가 임포트가 되지 않았다
import 패키지명.BuildConfig
다시 검색의 결과
그라들에서 아래 처럼 치면 된다길래 시도했지만... 실패
buildFeatures{ buildConfig = true }
아래 사이트를 통해
설정 -> 빌드 -> make project로 하니 해결되었다.
import문이 없어도 그라들에서 싱크해준 위 설정이 먹힌거 같다
https://hello-bryan.tistory.com/399
[Android] BuildConfig 오류 Cannot resolve symbol 'BuildConfig' 해결
Cannot resolve symbol 'BuildConfig' Activity 에서 앱 최초 생성했을 때나, Build > Clean Project 하면 발생하는데요, 이럴땐, 빌드하면 됩니다.. 오류없이 빌드 되고 나면, BuildConfig 를 못찾는다는 메시지는 안나
hello-bryan.tistory.com
❔Map과 HashMap
return hashMapOf( "serviceKey" to authKey, "returnType" to "json", "numOfRows" to "100", "pageNo" to "1", "sidoName" to sido, "ver" to "1.0" )
특정예제 코드를 통해서 실습을 하던도중
위와같이 hashMapOf를 쓰는것을 보게 되었다
기존에는 mapOf를 사용해봤었는데
hashMap은 무슨차이일까 검색하게 되었고
그중에서 설명이 괜찮은 몇 블로그 주소를 남기려고한다
https://work2type.tistory.com/entry/CS-Map%EA%B3%BC-HashMap%EC%9D%98-%EC%B0%A8%EC%9D%B4-TreeMap
[CS] Map과 HashMap의 차이? TreeMap?
최근 내가 듣는 CS 인강에서 HashTable이 업데이트되어 다시 들으면서 Map과 HashMap의 차이에 대해 공부할 겸 이번 포스팅에서는 Map과 HashMap 각각을 살펴보고, 각기 사용하는 알고리즘에 대해 공부해
work2type.tistory.com
https://medium.com/depayse/kotlin-collections-2-map-hashmap-treemap-linkedhashmap-76195842f0c8
[Kotlin] Collections 2 — Map (TreeMap, HashMap, LinkedHashMap)
Kotlin의 Map interface에 대한 overview와 TreeMap, HashMap, LinkedHashMap에 대해 자세히 다룹니다.
medium.com
⛔UnknownServiceException: CLEARTEXT communication to
에러가 발생했다
제목대로 에러가 났었는데
사실 이전에 java.lang.exceptionininitializererror 에러도 발생하였었고
에러 원인을 추적하면서
주소가 잘못된게 아닐까라는 생각에 도달되었다
처음에는 주소 끝에 "/" 표시가 없었다 http에 "s"를 붙이지도 않았고,
/를 사용하게 되니 java.lang.exceptionininitializererror 에러가 사라진 대신
UnknownServiceException to apis.data.go.kr not permitted by network security policy 에러가 발생하였다.
다시 검색...
아래 사이트대로 보안 이슈를 접하게 되어
http만 적은것을 확인했다
s를 붙이니 정상적으로 API요청을 통해 서버로부터 데이터를 받아오는것이다..
private const val DUST_BASE_URL = "https://apis.data.go.kr/B552584/ArpltnInforInqireSvc/"
https://dev-cho.tistory.com/28
통신 시 java.net.UnknownServiceException:CLEARTEXT communication to [URL] not permitted by network security policy 오류
이러한 오류를 보신 분들은 모두 서버와 통신을 시도하다가 발생하였을 것입니다. 오류 원인과 해결책은 다음과 같습니다. 오류 원인 : http의 보안 이슈로 인해 안드로이드9버전 부터는 직접 접
dev-cho.tistory.com
금일 회고
상태:😀
회고:
피곤하다
강의를 듣고, 실습을 하는데
계속 에러가 뜬다
다양한 에러라서 삽질을 계속 하게 되는거같다어떤때는 단순 호환성 이슈라서 안드로이드 플러그인을 업데이트하거나 버전업을 하게되면서 해결되었고,어떤것은 아예 이해가 안가는 에러라서 계속 찾게 되었다
계획했던 강의를 끝까지 듣는것은 하였지만,미세먼지 앱을 만들어서 공공데이터 포털에서 제공해주는 API를 통해 시도별 미세먼지 데이터를 받아오는 과정에서 계속 오류가 생긴다
오늘은 그것을 해결해야 잘 수 있지 않을까...
좋은 경험이라고 생각하며 잘 해결할 수 있으면 좋겠다
'개발공부 > 일지' 카테고리의 다른 글
다음글이 없습니다.이전글이 없습니다.댓글