Y
Y
Yarik Mamaev2018-02-11 20:16:02
Java
Yarik Mamaev, 2018-02-11 20:16:02

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;
    }
}

PS I know this is not allowed (protected void onCreate extends GuizActivitiy (Bundle savedInstanceState) {
) but I would like to know why this is not allowed!!
pps in the method
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

1 answer(s)
G
GavriKos, 2018-02-11
@Conqueror3

onCreate is not a class, it's a method. Methods cannot be extended, inherited, and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question