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"/>

最新文章

  1. docker容器与容器云读书笔记1
  2. grootJs 属性过滤器
  3. mysql 判空
  4. 大话数据结构(五)(java程序)——顺序存储结构的插入与删除
  5. ectouch第十一讲 之 ECTouch 菜单里如何添加文章链接
  6. [工作记录] Android OpenGL ES 2.0: square texture not supported on some device
  7. [转]Jmeter(一)-精简测试脚本
  8. html元素中class属性值多个空格分格是什么意思?
  9. Nginx GoAccess安装与配置
  10. hdu 1253 胜利大逃亡 (代码详解)解题报告
  11. AES128加密算法完整实现
  12. /etc/tolmcat/Server.xml 实例说明
  13. (https专业版)2018年1月5日高仿互站仿友价T5虚拟交易+实物交易商城-站长交易源码送手机版程序10套模版+首页微信登陆+头部下拉导航
  14. 房产地图google map的初步应用点滴.2)(转)
  15. 查看nginx cache命中率
  16. 设置NGINX进程分配至多核CPU提升性能
  17. js继承方式及其优缺点?
  18. [GO]tcp网络通信和实现
  19. Oracle中-事务-序列-视图-数据类型笔记
  20. 问题小记(MyBatis传参出现的小问题)

热门文章

  1. Object中的clone方法
  2. IIS10搭建FTP服务
  3. YAML 格式学习
  4. May 27th 2017 Week 21st Saturday
  5. kill 使用当前数据库的所有session
  6. 二分图最大权值匹配 KM算法 模板
  7. Visual Studio 发布 Windows Service小记
  8. HashMap对HashCode碰撞的处理
  9. win10 安装YII2
  10. Angular将填入表单的数据渲染到表格