自定义控件,继承自 ListView
2024-09-04 18:15:10
public class MyListView extends ListView { /**
* 如果在xml中创建并设置了style,就会调用三个参数的。
*
* @param context
* @param attrs
* @param defStyle
*/
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} /**
* 如果是在xml中创建这个控件并且没有指定style,会调用两个参数的
*
* @param context
* @param attrs
*/
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
String[] ss = {"abc", "123", "qwert", "asdf"};
ArrayAdapter<String> aa = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, ss);
setAdapter(aa);
} /**
* 在java代码中直接new一个自定义的 ListView,会调用一个参数的构造函数
*/
public MyListView(Context context) {
super(context);
}
}
布局文件:
<com.test.testlistview.MyListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myListView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
最新文章
- docker容器与容器云读书笔记1
- grootJs 属性过滤器
- mysql 判空
- 大话数据结构(五)(java程序)——顺序存储结构的插入与删除
- ectouch第十一讲 之 ECTouch 菜单里如何添加文章链接
- [工作记录] Android OpenGL ES 2.0: square texture not supported on some device
- [转]Jmeter(一)-精简测试脚本
- html元素中class属性值多个空格分格是什么意思?
- Nginx GoAccess安装与配置
- hdu 1253 胜利大逃亡 (代码详解)解题报告
- AES128加密算法完整实现
- /etc/tolmcat/Server.xml 实例说明
- (https专业版)2018年1月5日高仿互站仿友价T5虚拟交易+实物交易商城-站长交易源码送手机版程序10套模版+首页微信登陆+头部下拉导航
- 房产地图google map的初步应用点滴.2)(转)
- 查看nginx cache命中率
- 设置NGINX进程分配至多核CPU提升性能
- js继承方式及其优缺点?
- [GO]tcp网络通信和实现
- Oracle中-事务-序列-视图-数据类型笔记
- 问题小记(MyBatis传参出现的小问题)