kotlin中安卓listview实现
来源:互联网 发布:房地产数据网 编辑:程序博客网 时间:2024/06/09 16:56
Kotlin最近一段时间火啦起来,我想自己学习学习,这是我自己简单在as上写的代码,与大家分享
首先布局还是xml的形式
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.rxd.trykotlin.MainActivity"> <android.support.v7.widget.ListViewCompat android:id="@+id/recycle" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.ListViewCompat></RelativeLayout>
但是,MainActivity.kt中写的行驶略有不同
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mListView=findViewById(R.id.recycle)as ListView mListView.adapter=ForcastAdapter(items,this)}自定义适配器,其中注意构造参数前加val
class ForcastAdapter(val stringList: List<String>,val mContext:Context) : BaseAdapter() { override fun getItem(position: Int): Any { return stringList[position] } override fun getItemId(position: Int): Long { return position.toLong() } override fun getCount(): Int { return stringList.size } override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { val view=LayoutInflater.from(mContext).inflate(R.layout.item_forcast,parent,false) val text= view.findViewById(R.id.tv_iteforcast) as TextView text.text=stringList[position] return view }}
阅读全文
0 0
- kotlin中安卓listview实现
- Kotlin初探:用Kotlin实现Android的ListView列表
- Kotlin 与 listView
- Kotlin 与ListView的结合
- 使用kotlin写一个ListView
- Kotlin学习记录(三)—— 子线程获取数据,实现简单ListView
- Kotlin实现ViewPager的左右滑动和listview的简单使用
- 《Kotlin 程序设计》第十一章 Kotlin实现DSL
- Kotlin实现propertyAnimator
- kotlin实现登录逻辑
- Kotlin实现RadioFlexboxGroup组件
- Kotlin实现recyclerView列表
- < Kotlin > Kotlin For Gank.io (干货集中营Kotlin实现)
- Kotlin类、继承、接口实现
- Kotlin实现MVP设计模式
- Kotlin使用retrofit实现recyclerview
- listview实现
- 安卓3.0 的kotlin是用listview
- LeetCode 198. House Robber
- python的KNN算法基本实现
- fuzhuo---Problem 1205 小鼠迷宫问题
- 工程大小优化之图片资源
- C#代码操作/编辑Word的基础知识
- kotlin中安卓listview实现
- nyoj 417 死神来了 鸽巢定理
- 服务器常用的状态码及其对应的含义
- jsoncpp 解析json
- 南阳理工oj 题目85 有趣的数 Cantor数表
- 第一篇博客
- 【J2EE规范】什么是JNDI
- UESTC 1635 琵琶弦上说相思,当时明月在,曾照彩云归 拓扑排序、bfs
- js 获取选中某列的和遇到的一系列问题