【发布时间】:2016-01-18 16:49:24
【问题描述】:
其实我是想把一个变量类型和Id传入一个类来初始化变量。
喜欢,Button myButton=new MyClass(Button, myButtonId);
这里Button是变量类型,myButtonId是xml中的id。
并且类(方法)将返回类似(Button)findViewById(R.id.myButtonId);
为此我写了
Button myButton=new MyClass(Button, myButtonId);
Android Studio 建议我
private class MyClass extends Button {
public MyClass(Object p, Button myButtonId) {
super();
}
}
super(); 行有错误。
我不知道要做更多。 有什么建议吗?
【问题讨论】:
-
你可以使用setter和getter
-
在 super() 中使用什么;因为有错误?
-
检查构造函数@grepcode.com/file/repository.grepcode.com/java/ext/… 只是传递上下文
-
类会返回类似的东西——类不会返回,它们会封装。我很困惑你为什么要这样做?
-
其实我是说方法