android - 自定义继承listview的三个重写的方法怎么理解
PHPz
PHPz 2017-04-17 15:08:18
[Android讨论组]

如图,第一次用自定义继承listview的写法,不是很理解,之前都用布局用的。如何理解这个三个方法,一定要写全吗?

public class DefineListView extends ListView {

    public DefineListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public DefineListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DefineListView(Context context) {
        super(context);
    }
PHPz
PHPz

学习是最好的投资!

全部回复(1)
黄舟

在java代码中直接new一个DefineListView ,会调用一个参数的构造函数,比如
DefineListView defineListView = new DefineListView (context)
如果是在xml中创建这个控件并且没有指定style,会调用两个参数的,如

<com.example.DefineListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></com.example.DefineListView>

如果在xml中创建并设置了style,就会调用三个参数的。

<com.example.DefineListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/myStyle"></com.example.DefineListView>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号