Android 多构造函数和空值
1:从一节课开始测验课:Android 多构造函数和空值,android,constructor,Android,Constructor,1:从一节课开始测验课: Med.setQuiz(new Quiz(Cat, null)); 问答课: public Quiz(final String category, TextView outputTxt) { MyTxt = outputTxt; StartAct(category); } 2:从另一个班级开始测验课程: Quiz MyNewQ = new Quiz(null, Txt); 首先:我开始上课,用StartAct(类别)设置一
Med.setQuiz(new Quiz(Cat, null));
问答课:
public Quiz(final String category, TextView outputTxt) {
MyTxt = outputTxt;
StartAct(category);
}
2:从另一个班级开始测验课程:
Quiz MyNewQ = new Quiz(null, Txt);
首先:我开始上课,用StartAct(类别)设置一些值强>
然后我再次使用了类:测验(null,Txt)但是当我使用它时,StartAct值设置为null
但是我想使用我在第一堂课[quick(Cat,null)]中设置的值
如何执行此操作?您可以使用如下静态值:
public class Quiz{
private static String category;
public Quiz(final String category, TextView outputTxt) {
// check category is not null or empty, don't set if it is
// which means that we must call the constructor with a valid category
// the first time or perhaps set a default value
if(category!=null && !category.equals("")){
Quiz.category = category;
}
MyTxt = outputTxt;
StartAct(Quiz.category);
}
}