0

在此处输入图像描述我想对 Android 应用程序中已有的布局资源进行简单调用,如下所示。我需要做的就是能够使用诸如 myInteger 之类的变量(具有诸如 1、2、3 之类的值)并调用 R.layot

4

3 回答 3

0

在你的 android studio 中尝试Build>Rebuild ProjectBuild>Clean Project 。

于 2017-07-13T17:48:00.523 回答
0

尝试使用(myView.findViewById(R.id....) as TextView).text = animal.name!!

或者,如果您kotlin-android-extensions在此类中使用检查导入。如果您从导入的不同布局中查看具有重复 id 的视图,您也不能使用扩展

于 2017-07-13T17:48:14.710 回答
0

来自土耳其的哈桑兄弟你好。用这个改变你的代码好吗?

class AnmailAdapter(val context: Context, val listOfAnmail: ArrayList<Anmail> ): BaseAdapter() {

override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {

    val anmail = listOfAnmail[p0]

    val view = LayoutInflater.from(context).inflate(R.layout.activity, p2, false)
    val tvName = view.findViewById<TextView>(R.id.tvName)
    val tvDesc = view.findViewById<TextView>(R.id.tvDes)
    val imgView = view.findViewById<ImageView>(R.id.imgView)

    tvName.text = anmail.name
    tvDesc.text = anmail.des
    imgView.setImageResource(anmail.image!!)

    return view
}

override fun getItem(p0: Int): Any {
    return listOfAnmail[p0]
}

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

override fun getCount(): Int {
    return listOfAnmail.size
}
}

如果你的 kotlin 版本低于我;

val tvName = view.findViewById<TextView>(R.id.tvName)

反而;

val tvName = view.findViewById(R.id.tvName) as TextView
于 2017-07-14T08:39:29.420 回答