Android Stuido 方法参数 p0,p1

Android Stuido 方法参数 p0,p1

参考文献

https://stackoverflow.com/questions/49219439/incorrect-variable-names-in-overridden-methods

问题描述

刚刚升级了Android Studio的版本到3.3,在使用RecyclerView的时候出现了下面的问题:

在实现RecyclerView.Adapter的时候,方法的参数出现 p0 , p1 这样的情况。

class CommonAdapter : RecyclerView.Adapter<MyViewHolder>() {
    override fun getItemCount(): Int {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onBindViewHolder(p0: MyViewHolder, p1: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): MyViewHolder {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}

问题解决

出现了这个问题之后,找了很多资料,有的说没有想在对应API的源码,有的说得修改AndroidStudio的配置文件,有的说得修改SDK的路径,但是最终都没有解决。

最终在 stackoverflow 上找到了解决办法,原来是引用了 28 的Design包。这个问题是API 28 的固有的问题,并不是自己配置错误导致的问题,讲28的包改为27的包就可以解决了。

implementation 'com.android.support:design:28.0.0'

将28的包改为如下所示的27的包以后,问题解决了。

implementation 'com.android.support:design:27.0.0'

修改后实现方法的效果如下:

class CommonAdapter : RecyclerView.Adapter<MyViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun getItemCount(): Int {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onBindViewHolder(holder: MyViewHolder?, position: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

}
posted @ 2019-03-18 16:09  鲁迅认识的那只猹  阅读(665)  评论(0编辑  收藏  举报