[英]The constructor ArrayAdapter<ArrayList<HashMap<String, String>>>(Context, int, ArrayList<HashMap<String, String>>) is undefined
[英]in Kotlin ArrayAdapter need (Context context,int resource) as parameter but i want as a string in the ArrayList how h can do that?
class Word(var mDefultTranslation: String, var mArabicTranslation: String ) {
fun Word (defultTranslation : String , arabicTranslation : String ){
mDefultTranslation = defultTranslation
mArabicTranslation = arabicTranslation
}
}
val words = arrayListOf<Word>()
words.add( Word("one","two" ))
val wordAdapter = WordAdapter (this, word??)
如果您只想使用带有ArrayAdapter
的ListView
,则可以使用以下方法入门:
val adapter = object : ArrayAdapter<Word>(this, android.R.layout.simple_list_item_2, android.R.id.text1, words) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view = super.getView(position, convertView, parent)
val text1 = view.findViewById(android.R.id.text1) as TextView
val text2 = view.findViewById(android.R.id.text2) as TextView
text1.setText(words[position].mDefultTranslation)
text2.setText(words[position].mArabicTranslation)
return view
}
}
listview.adapter = adapter
将第三个参数放入您的WordAdapter
。
class WordAdapter(context: Context, @LayoutRes resource: Int, private val wordList: ArrayList<Word>) : ArrayAdapter<Word>(context, resource)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.