小编Wae*_*låh的帖子

使用 Kotlin 在 Android 中创建自定义 Spinner 适配器

我正在尝试使用Spinner自定义适配器来显示带有如下文本的图像

我想要的结果

但我有很多未解决的参考资料,所以我认为我做了一些非常错误的事情

我有两个片段,微调器位于第二个片段内 custome_spinner.xml,是自定义布局文件

Android Studio 版本 3.1.2,kotlin_version = '1.2.30'以及gradle:3.1.2

CustomeSpinnerAdapter.kt

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter

class customeSpinnerAdapter : BaseAdapter {
    override fun getItem(p0: Int): Any {
        return flag.length
    }

    override fun getItemId(p0: Int): Long {
        return null
    }

    override fun getCount(): Int {
        return 0
    }

    val country: String
    val flag: String
    fun customeSpinnerAdapter(context: Context, name: String, image: String) {
        this.country = name
        this.flag = image

        val inflater …
Run Code Online (Sandbox Code Playgroud)

kotlin android-studio

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android-studio ×1

kotlin ×1