1:从类中启动Quiz类:
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 。< / p>
但是我想使用我在头等[测验(Cat,null)]中设置的值
我该怎么做?
答案 0 :(得分:0)
你可以使用这样的静态值:
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);
}
}