Solution Challenge 3


#1

// Global variable

private int[] mArray=new int[4];

// On ActivityResult

@Override
public void onActivityResult(int requestCode,int resultCode,Intent data)
{
if(resultCode==RESULT_OK) {
mIsCheater = data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN, false);
}
if(mIsCheater==true) {
int n;
n = (mCurrentIndex) % mAnswerKey.lenght;
mArray[n]=n;
}

}//end of onActivityResult

//NextButton
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mAnswerKey.length;
updateQuestion();
if(mCurrentIndex != mArray[mCurrentIndex])
{ mIsCheater=false;
}else
mIsCheater=true;
}
});

// And for Change The Device Configuration --> Add to onSaveInstanceState
savedInstance.putIntArray(“Array_KEY”,mArray);

//And Get it into OnCreate
mArray=savedInstanceState.getIntArray(“Array_KEY”);

Please don’t copy…May be I CHANGED VARIABLEs & METHODs names.


#2

[quote=“Madhid”]// Global variable

private int[] mArray=new int[4];

// On ActivityResult

@Override
public void onActivityResult(int requestCode,int resultCode,Intent data)
{
if(resultCode==RESULT_OK) {
mIsCheater = data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN, false);
}
if(mIsCheater==true) {
int n;
n = (mCurrentIndex) % mAnswerKey;
mArray[n]=n;
}

}//end of onActivityResult

[/quote]
this code is very good, and solved my question.
but there is some wrong about this line: n = (mCurrentIndex) % mAnswerKey;
It shoud be: n = (mCurrentIndex) % mAnswerKey.length;


#3

Yes,I am sorry,…edited
Thanks…