[英]Super Activity class dialog box listeners handling in sub class activity
Hi I have created generic Activity class which have a dialog box(with DatePicker) in it. 嗨,我创建了一个通用Activity类,其中有一个对话框(带有DatePicker)。 Extending it allover the application.
将其扩展到整个应用程序。 I would like to handle the listeners of the date selector in sub class activity.
我想在子类活动中处理日期选择器的侦听器。 I tried with implementing a interface in the super class and override the same in sub class.
我尝试在超类中实现接口,并在子类中重写相同的接口。 and i was struck at overriding the same in sub class.
我在子类中重写相同的方法而感到震惊。
Now my question is.. .Is this really a bad idea...? 现在我的问题是..这真的是个坏主意吗? Any alternate for this approach.
此方法的任何替代方法。
Got the solution to my question All you have to do is create a abstract method is super class as 得到了我的问题的解决方案,您所要做的就是创建一个抽象方法,即super class as
public abstract class SuperActivity{
onCreateDialog(){
//date picker with date select listeners and add get the selected date;
// call onDateChanged() in the date selected listener in the super class
}
public abstract onDateChanged();
}
Implement the onDateChanged() method in SubClass Then whenever you changed the date in super class.. sub class onDateChanged() method will be called. 在SubClass中实现onDateChanged()方法然后,每当您在超类中更改日期时,就会调用子类的onDateChanged()方法。
class SubCActivity extends SuperActivity(){
public void onDateChanged(){
// handling
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.