Skip to content

Instantly share code, notes, and snippets.

@gsanthosh91
Last active June 20, 2018 10:25
Show Gist options
  • Select an option

  • Save gsanthosh91/d2ccc86f07c57fe890fc70cb41b9fa29 to your computer and use it in GitHub Desktop.

Select an option

Save gsanthosh91/d2ccc86f07c57fe890fc70cb41b9fa29 to your computer and use it in GitHub Desktop.
Android Live Template for Listview BaseAdapter in Kotlin
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
class ${NAME}(context: Context, list: List<${LIST_MODEL}>) : BaseAdapter() {
private val mContext: Context;
private val list: List<${LIST_MODEL}>
init {
this.mContext = context;
this.list = list
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view: View
if (convertView == null) {
view = LayoutInflater.from(parent!!.context).inflate(R.layout.${item_layout}, parent, false)
view.tag = ViewHolder(view)
} else {
view = convertView
}
val viewHolder = view.tag as ViewHolder
val ${LIST_MODEL} = getItem(position)
//viewHolder.title.text = ${LIST_MODEL}
return view;
}
override fun getItem(position: Int): ${LIST_MODEL} {
return list.get(position)
}
override fun getItemId(position: Int): Long {
return position.toLong();
}
override fun getCount(): Int {
return list.size;
}
private class ViewHolder(val view : View) {
val title = view.title
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment