subclass

Extending MediaController for android

泄露秘密 提交于 2019-12-17 16:29:49
问题 I am using a VideoView and the MediaController for an app I am working on. I simply wanted to have the MediaController appear on top of my VideoView but apparently you can't do that very easily. I attempted to use the setAnchorView method to my VideoView id, but that didn't work. No matter what I do, the MediaController is always at the bottom of my screen. With that said, I did some research and it looks as if I go about extending MediaController , I can change position and other properties.

Instance is an “object”, but class is not a subclass of “object”: how is this possible?

大城市里の小女人 提交于 2019-12-17 16:19:14
问题 How is it possible to have an instance of a class which is an object , without the class being a subclass of object ? here is an example: >>> class OldStyle(): pass >>> issubclass(OldStyle, object) False >>> old_style = OldStyle() >>> isinstance(old_style, object) True 回答1: In Python 2, type and class are not the same thing, specifically, for old-style classes, type(obj) is not the same object as obj.__class__ . So it is possible because instances of old-style classes are actually of a

Protected fields not visible to subclasses

喜欢而已 提交于 2019-12-17 16:06:43
问题 I'm writing a custom view that directly extends android.view.View . If I try to access fields mScrollX or mScrollY , I see an error that the field "cannot be resolved or is not a field." The source code for android.view.View has mScrollX, mScrollY, and similar variables declared protected . How is it that my direct subclass cannot access protected fields of its parent class? (Classes like ScrollView apparently can.) P.S. I realize that I can call getScrollX() , but I want to update these

Private members in Java inheritance

风流意气都作罢 提交于 2019-12-17 15:45:16
问题 I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members. Can someone explain this to me. I am now totally confused. 回答1: No, the private member are not inherited because the scope of a private member is only limited to the class in which it is defined. Only the public and protected member are inherited. From the Java Documentation, Private Members in a Superclass A subclass does not

Why subclass in another package cannot access a protected method?

房东的猫 提交于 2019-12-17 10:51:33
问题 I have two classes in two different packages: package package1; public class Class1 { public void tryMePublic() { } protected void tryMeProtected() { } } package package2; import package1.Class1; public class Class2 extends Class1 { doNow() { Class1 c = new Class1(); c.tryMeProtected(); // ERROR: tryMeProtected() has protected access in Class1 tryMeProtected(); // No error } } I can understand why there is no error in calling tryMeProtected() since Class2 sees this method as it inherits from

Reclassing an instance in Python

有些话、适合烂在心里 提交于 2019-12-17 10:23:00
问题 I have a class that is provided to me by an external library. I have created a subclass of this class. I also have an instance of the original class. I now want to turn this instance into an instance of my subclass without changing any properties that the instance already has (except for those that my subclass overrides anyway). The following solution seems to work. # This class comes from an external library. I don't (want) to control # it, and I want to be open to changes that get made to

Access subclass fields from a base class in Java

泄露秘密 提交于 2019-12-17 09:58:25
问题 I have a base class called Geometry from which there exists a subclass Sphere : public class Geometry { String shape_name; String material; public Geometry() { System.out.println("New geometric object created."); } } and a subclass: public class Sphere extends Geometry { Vector3d center; double radius; public Sphere(Vector3d coords, double radius, String sphere_name, String material) { this.center = coords; this.radius = radius; super.shape_name = sphere_name; super.material = material; } } I

Subclassing Python dictionary to override __setitem__

亡梦爱人 提交于 2019-12-17 05:41:11
问题 I am building a class which subclasses dict , and overrides __setitem__ . I would like to be certain that my method will be called in all instances where dictionary items could possibly be set. I have discovered three situations where Python (in this case, 2.6.4) does not call my overridden __setitem__ method when setting values, and instead calls PyDict_SetItem directly In the constructor In the setdefault method In the update method As a very simple test: class MyDict(dict): def __setitem__

How to call textField that is a inside of UITableViewCell (swift)

浪子不回头ぞ 提交于 2019-12-14 04:21:48
问题 I have a UITextField that is inside of UITableViewCell : func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TextFieldTableViewCell let textField: UITextField = cell.textField let detail = self.detailItem textField.text = detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description print() return cell } How can pass that

Confused with Constructors and Subclasses

青春壹個敷衍的年華 提交于 2019-12-14 03:53:20
问题 I'm having trouble understanding the concept of using constructors with subclasses. Here is the parent class: public class A { public A() { System.out.println("The default constructor of A is invoked"); } } The child class: public class B extends A { public B(String s) { System.out.println(s); } } And my main method: public class C { public static void main (String[] args) { B b = new B("The constructor of B is invoked"); } } When I run C, the output I get is The default constructor of A is