Android Application
Kotlin 어댑터 뷰(Adaptor View) : 갤러리(Gallery)
작성자 임베디드코리아
작성일23-09-25 02:14
조회1,585회
댓글0건
------------------------------------------------------------------------------------
activity_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">
<Button
android:text="Gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnGallery" />
<ImageView
android:layout_width="match_parent"
android:layout_height="500dp"
android:id="@+id/GImageView" />
</androidx.constraintlayout.widget.ConstraintLayout>
------------------------------------------------------------------------------------
MainActivity.kt
------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
private val GALLERY = 1
private lateinit var galleryBTN: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
galleryBTN = findViewById(R.id.btnGallery)
galleryBTN.setOnClickListener{
val intent: Intent = Intent(Intent.ACTION_GET_CONTENT)
intent.setType("image/*")
startActivityForResult(intent,GALLERY)
}
}
}