Last active
June 20, 2018 10:25
-
-
Save gsanthosh91/d2ccc86f07c57fe890fc70cb41b9fa29 to your computer and use it in GitHub Desktop.
Android Live Template for Listview BaseAdapter in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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