Answer the question
In order to leave comments, you need to log in
Why can't the onCreate class inherit variables from the main class?
public class GuizActivity extends AppCompatActivity {
private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private TextView mTV;
private int mCurrentIndex = 0;
TrueFalse[] mQuesitonBank = new TrueFalse[]{
new TrueFalse(R.string.onn, true),
new TrueFalse(R.string.inn, true),
new TrueFalse(R.string.gcc, true),
};
@Override
protected void onCreate extends GuizActivitiy (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guiz);
mTV = (TextView) findViewById(R.id.TV);
final int question = mQuesitonBank[mCurrentIndex].getQuestion();
mTV.setText(question);
mTrueButton = (Button) findViewById(R.id.button_true);
mFalseButton = (Button) findViewById(R.id.button_false);
mNextButton = (Button) findViewById(R.id.button_next);
mNextButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
mCurrentIndex = (mCurrentIndex++) % mQuesitonBank.length;
int guestion = mQuesitonBank[mCurrentIndex].getQuestion();
mTV.setText(question);
}
});
}
mTrueButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Toast.makeText(GuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
}
});
mFalseButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Toast.makeText( GuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
}
});
}
protected boolean onCreateOptionMeny(Menu menu){
return true;
}
}
mNextButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
mCurrentIndex = (mCurrentIndex++) % mQuesitonBank.length;
int guestion = mQuesitonBank[mCurrentIndex].getQuestion();
mTV.setText(question);
}
});
do we create two new variables or redefine them?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question