变化
if (mQuestionNumber < mQuestionLibrary.getQuestionCount())
updateQuestion();
else
//Show next screen
setContentView(R.layout.scoredisplay);
到
if (mQuestionNumber < mQuestionLibrary.getQuestionCount())
updateQuestion();
else
{
Intent intent = new Intent(QuizActivity.this,ScoreDisplay.class);
intent.putExtra("score",mScore);
startActivity(intent);
}
创建一个名为ScoreDisplay新安装插件,并接收来自QuizActivity的mScore
值,通过使用该
int score;
score= getIntent().getIntExtra("score",0);
最后显示的比分ScoreDisplay到你的textView
。
textview.setText(score+"");
ScoreDisplay.java
public class ScoreDisplay extends AppCompatActivity {
TextView myScore;
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scoredisplay);
score= getIntent().getIntExtra("score",0);
myScore = (TextView)findViewById(R.id.endingScore);
myScore.setText(score+"");
}
}
添加下面的代码到你的mainfest解决死机问题。
<activity android:name=".ScoreDisplay"></activity>
AndroidMainfest FullCode
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mgilani.co.multipleqa">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".QuizActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScoreDisplay"></activity> //new line
</application>
</manifest>
我最后的XML被称为scoredisplay.xml –
如果你去我QuizActivity.java的底部,然后你会看到;公共无效endingScore(视图视图){ mfinalScoreView = mScore; –
这就是我需要帮助的地方,代码应该去那里更新我的最终xml布局中的值0? –