【发布时间】:2014-11-24 02:02:33
【问题描述】:
我想为 android 创建自己的 UI 小部件类,它是 LinearLayout 的继承类。
public class MyOwnClass extends LinearLayout {
...
public void setSomeProperties(Object properties) { ... }
但是 LinearLayout 有很多公共方法,我想要在我的类中定义的唯一公共方法。如何让 MyOwnClass 的实例无法访问 LinearLayout 的所有公共方法?
myOwnClass.setSomeProperties(properties); // only this should be accesible
myOwnClass.setBackground(...); // this should'nt be accesible
【问题讨论】:
-
但是方法太多了..我不想把它们都放在我的课上
-
“但是 LinearLayout 有很多公共方法,我想要我在我的类中定义的唯一公共方法”——你别无选择,只能拥有“很多公共方法”,如这些在
View上定义为公开的,您需要从View继承来创建您自己的“UI 小部件类”。例如,setBackground()is defined onViewas beingpublic,因此您无法将其设为public以外的任何内容。 -
这很令人沮丧
标签: java android class inheritance private