コードの一部を貼り付けます。Picasso を使用して、Url から画像を imageview にレンダリングします。これは、すべてを最適に処理するため、良い方法です。
import kotlinx.android.synthetic.main.activity_login.*
class LoginActivity : AppCompatActivity() {
val imageReturned = 100
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
//With when we select the request code we asked in the StartActivityForResult
when(requestCode){
//that will be imageReturned
imageReturned -> Picasso.with(this@LoginActivity)
.load(data?.getStringExtra("theUrl")).into(image_view)
//now what we did here was use Picasso to load
//the URL in the StringExtra "theUrl" into image_view,
//image_view will be the synthetic bound of anko for it to
//work you have to `import kotlinx.android.synthetic.main.activity_login.*`
}
}
}
これは、XML からビューをバインドし、anko DSL を使用してそれを達成する場合は、findViewById(android.R.id.content) で contentView を取得し、id で Imageview を検索してから設定する必要があります。あそこでやったのと同じ。
それが役に立てば幸い